isolate scope与scope的区别

普通的$scope可以获取到父类的属性,如同prototype继承一样

isolate $scope则只能找到它自己的属性

原理很简单:$scope将prototype直接指向了其父$scope,而$scope没有,居然其它的属性是一样的,但是在进行属性查找时是有分别的。

在$rootScope中:
$new: function(isolate, parent) {
        var child;

        parent = parent || this;

        if (isolate) {
          child = new Scope();
          child.$root = this.$root;
        } else {
          // Only create a child scope class if somebody asks for one,
          // but cache it to allow the VM to optimize lookups.
          if (!this.$$ChildScope) {
            this.$$ChildScope = function ChildScope() {
              this.$$watchers = this.$$nextSibling =
                  this.$$childHead = this.$$childTail = null;
              this.$$listeners = {};
              this.$$listenerCount = {};
              this.$id = nextUid();
              this.$$ChildScope = null;
            };
            this.$$ChildScope.prototype = this;
          }
          child = new this.$$ChildScope();
        }
        child.$parent = parent;

 

你可能感兴趣的:(scope)