1 <body> 2 <div id="box"></div> 3 </body> 4 <script> 5 var box = document.getElementById("box") //this.data.name => this.name 6 this.data = { 7 name: 'shun' 8 9 } 10 console.log(this, this.data, 'pppppp') 11 box.innerHTML = this.data.name 12 13 function proxy(vm, source, key) { 14 Object.defineProperty(vm,key, { 15 get() { 16 return vm[source][key] 17 }, 18 set(newval) { 19 vm[source][key] = newval 20 } 21 }) 22 } 23 24 proxy(this, 'data', 'name') 25 26 console.log(this.name, '11111111') //shun