0

我正在尝试使用代理拦截获取和设置操作。设置完美,但在无限循环中触发“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)

4

1 回答 1

0

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

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)

于 2016-03-28T18:18:05.287 回答