Proxy .__proto__ is not getPrototypeOf?

John Barton johnjbarton at google.com
Mon May 5 13:21:22 PDT 2014


On Mon, May 5, 2014 at 11:44 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On May 5, 2014, at 10:40 AM, John Barton wrote:
>
> 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().
>
> For example:
>   var aPrototype = {foo: 'foo'};
>   var handler = {
>   get: function(target, name, receiver) {
>   console.log('   (Proxy handler \'get\' called for name = ' + name +
> ')');
>   return target[name];
>
>
> the above line needs to be:
>                  return Reflect.get(target, name, receiver);
>
> Object.prototype.__proto__ is an accessor property and to work correctly
> it needs to have the originally accessed object passed at the this value.
>  That's why 'get' handlers (and others) have a 'receiver' argument.
>

Thanks! With your change the example works. Unfortunately I'm still
confused.

Before I reduced the code to a short example I was using
Object.getPrototypeOf(obj), like:
  https://gist.github.com/johnjbarton/30c3e72d51d9d64e36d1
rather than targt[name] my first examples shows. It also fails the same
way.

Let me rephrase my question: why is the Proxy get even called in this case?

jjb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140505/529d1eee/attachment.html>


More information about the es-discuss mailing list