Proxy .__proto__ is not getPrototypeOf?
Tom Van Cutsem
tomvc.be at gmail.com
Mon May 5 13:13:52 PDT 2014
2014-05-05 19:40 GMT+02:00 John Barton <johnjbarton at google.com>:
> I'm hoping someone can explain this result which surprises me.
> If I create an object with a Proxy-ed prototype, the resulting object does
> not obey .__proto__ equal Object.getPrototypeOf().
There's no such equivalence, even for regular objects. `__proto__` is just
a property name, so `proxy.__proto__` just triggers the "get" trap, as any
normal property access. If the proxy should treat it specially, you need to
special-case the name `__proto__` in the "get" trap. However, as Allen
points out, forwarding should work correctly as long as you also forward
the "receiver" binding using the Reflect.get method.
> At this point, I expected
> hasProxyAsProto.__proto__ === aProxy
> but it it not true. Moreover, the operation
> calls the Proxy handler get function with name === '__proto__': that makes
> no sense as hasProxyAsProto is not a Proxy.
If an object inherits from a proxy, then any property access for a non-own
property will traverse the prototype chain. If it hits a proxy, that
proxy's "get" trap is called.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss