添加__ob__属性,值为Observer

    function def (obj, key, val, enumerable) {
      //obj 为观察数据对象,eg :{a:1}
      //key 为 __ob__
      //val 为 Observer{
          dep: Dep{id: 2subs: []},
          value: {a: 1},
          vmCount: 0,
      }
      
      Object.defineProperty(obj, key, {
        value: val,
        enumerable: !!enumerable,
        writable: true,
        configurable: true
      });
    }
    
        /**
     * Walk through all properties and convert them into
     * getter/setters. This method should only be called when
     * value type is Object.
     */
    Observer.prototype.walk = function walk (obj) {
      var keys = Object.keys(obj);
      for (var i = 0; i < keys.length; i++) {
        defineReactive$$1(obj, keys[i]);
      }
    };
    
    //判断是不是obj
     function isObject (obj) {
      return obj !== null && typeof obj === 'object'
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

iqing2012
19 声望0 粉丝

天青色,等烟雨


« 上一篇
插入排序
下一篇 »
vue数组变异