我正在尝试使用代理拦截获取和设置操作。设置完美,但在无限循环中触发“RangeError:超出最大调用堆栈大小”。我试图在拦截期间简单地记录并返回默认行为。
在职的:
testobject = {}
testobject = new Proxy(testobject, {
set(target, property, value, receiver) {
console.log("setting", target, property, value, receiver)
return(Reflect.set(target, property, value, receiver))
}
})
testobject.done = true
console.log(testobject.done)
破碎的:
testobject = {}
testobject = new Proxy(testobject, {
get(target, property, receiver) {
console.log("getting", target, property, receiver)
return(Reflect.get(target, property, receiver))
},
set(target, property, value, receiver) {
console.log("setting", target, property, value, receiver)
return(Reflect.set(target, property, value, receiver))
}
})
testobject.done = true
console.log(testobject.done)