ES6 用proxy进行预处理
//proxy 代理 增强对象和函数(方法) 生命周期 真正方法执行之前预处理 let obj={ add:function(){ return val+100; }, name:'I am jun' } console.log(obj.add(100)); console.log(obj.name); let pro=new Proxy({ add:function(){ return val+100; }, name:'I am jun' },{ //预处理机 get:function(target,key,property){ console.log(target); console.log(key); console.log(property); console.log('come in Get'); return target[key]; }, set:function(target,key,value,receiver){ //value是要改变的值 console.log('setting ${key}=${value}'); return target[key]=value+'111'; } }); console.log(pro.name) pro.name='nl' console.log(pro.name) //apply是内部调用的方法 let target=function(){ return 'I am from China' } let handler={ apply(target,ctx,args){ console.log('do apply'); return Reflect.apply(...arguments); } } //proxy中两个对象 let pro1=new Proxy(target,handler); console.log(pro1());