SOURCE

var a = {
       name: 'h',
       age: '18'
   }
   function test() {
       this.arr = []
       this.watch = function (prop, fn) {
           this.arr.push(fn)
           var that  =this
           Object.defineProperty(a, prop, {
               get:function () {
                   console.log('取到了')
               },
               set:function (value) {
                   console.log('执行了')
                   that.arr[0]()
               }
           })
       }
   }
   Object.defineProperty(a, 'prop', {
       get:function () {
           console.log('取到了')
       },
       set:function (value) {
           this.arr[0]()
       }
   })
   var watcher = new test()
   watcher.watch('name', function () {
       console.log('被我监听到了')
   })
    a.name = 'hhh'
console 命令行工具 X clear

                    
>
console