问题描述
我正在使用代理服务器,我的目标是遵守某些阵列上的操作。特别是我想在添加或删除项目时运行一些代码。我目前拥有的example如下:
const makeProxy = (xs) =>
new Proxy(xs,{
set(array,prop,value,receiver) {
console.log(`Set ${String(prop)} -> ${value}`);
return Reflect.set(array,receiver);
},deleteProperty(array,prop) {
console.log(`Delete ${String(prop)} | ${array[prop]}`);
return Reflect.deleteProperty(array,prop);
},});
const xs = makeProxy([]);
xs.push(10,20,30,40);
console.log("==========");
xs.splice(0,1);
console.log("==========");
xs.shift();
console.log("==========");
console.log(xs);
我所要解决的问题与代理服务器的deleteProperty
部分有关。当在数组上调用splice
和shift
之类的方法时,我真的很想知道要删除哪些元素。有没有很好的方法可以做到这一点?在deleteProperty
方法中,我似乎没有必要的信息,也许这不是正确的地方?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)