标签:start handler 意思 property rop 属性 方法 声明 set
let pro = new Proxy({ //方法体 add:function(val){ return val+100; }, name:‘ananiah‘ },{ //预处理机制 get set apply //get 得到属性前预处理 get:function(target,key,property){ console.log(target); //{add: ƒ, name: "ananiah"} console.log(key); //name return target[key] }, set:function(target,key,value,receiver){ console.log(`setting ${key} = ${value}`); //setting name = 代理 //返回之后打印出来的才会改变 return target[key] = value + ‘123‘; } }); console.log(pro.name); pro.name=‘代理‘; console.log(pro.name); //name 代理123 //apply let target = function(){ return ‘ananiah‘; } let handler = { apply(target,ctx,args){ console.log(‘apply start‘); return Reflect.apply(...arguments); //apply start } }; let proxx = new Proxy(target,handler); //调用 console.log(proxx()) //ananiah
标签:start handler 意思 property rop 属性 方法 声明 set
原文地址:https://www.cnblogs.com/Ananiah/p/11073690.html