代理获取 RangeError

Proxy Getting RangeError

我正在尝试使用代理拦截获取和设置操作。设置工作完美,但在无限循环中获取触发器 "RangeError: Maximum call stack size exceeded"。我试图在拦截期间简单地记录日志,并且 return 默认行为。

工作:

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)

我通过删除接收器参数解决了这个问题。

testobject = {}
testobject = new Proxy(testobject, {
 get(target, property) {
  console.log("getting", target, property)
  return(Reflect.get(target, property))
 },
 set(target, property, value) {
  console.log("setting", target, property, value)
  return(Reflect.set(target, property, value))
 }
})
testobject.done = true
console.log(testobject.done)