vue-源码

62次阅读

共计 566 个字符,预计需要花费 2 分钟才能阅读完成。

添加__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'}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

正文完
 0