I have a need to reference the current Proxy
instance from inside its own handler. I haven't seen this mentioned in any of the documentation I've read and I'm just curious if there's any natural way to do this.
The thing is, inside the handler object, this
naturally refers to the handler, not the Proxy
it is the handler of.
For example:
var ProxyHandler = {
get: function(object, property) {
var thisProxy = ??? // how to reference myProxy from here?
}
};
var someObj = {foo: "bar"};
var myProxy = new Proxy(someObj, ProxyHandler);
console.log(myProxy.foo);
The signature of a Proxy
get
handler isso since you do
myProxy.foo
, thereceiver
argument will bemyProxy
following the standard logic for property access context.