最近在学习es中的proxy代理的操作发现如果我定义了一个对象为:
var phone = {
number: 10068,
changeNumber(nu)?{
this.number = number
}
}
之后再使用Proxy代理
var proxy = new Proxy(phone,?{
get: function (target, key, proxy)?{
var value = target[key];
if (typeof value === 'function')?{
return function (...args)?{
console.log(`执行 ${key} 方法`);
return Reflect.apply(value, target, args)
}
} else {
console.log(`读取参数:${key}`);
return value
}
}
})
console.log(proxy.number);//===> 读取参数:number 10068 proxy.changeNumber(1231231233213)//===> 执行?changeNumber?方法
我可以理解代理的为get
读取方法,但是不能理解调用方法中的那个...args
是怎么传值过去的,希望可以解答一下?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…