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