为什么gethanler中的console.log接收器值导致错误?

I am learning ES6 Proxy, and try to understand param receiver in a get trap, so I tried to console.log the receiver value. But when run in nodejs, it causes an error:

RangeError:超出最大调用堆栈大小
let proxy = new Proxy({}, {
  get (target, key, receiver) {
    console.log('receiver:', receiver)
  }
})
let obj = Object.create(proxy)
console.log(obj)

I want to know what is causing this error, and how to test receiver's reference in different situations.

评论
过路人
过路人

我希望以下代码将有助于解决您的问题。

let proxy = new Proxy({}, {
    get: function (target, key, receiver) { // I hope that this line should 
 be the issue.
        console.log('receiver:' + receiver);
    }
});
let obj = Object.create(proxy)
console.log(obj)
点赞
评论