but that's exactly what I've replied to you already?
Once again, `__proto__` is spec'd in the `Object.prototype` like this:
```javascript
Object.defineProperty(
Object.prototype,
'__proto__',
{
configurable: true,
get: function () {
return Object.getPrototypeOf(this);
},
set: function (proto) {
Object.setPrototypeOf(this, proto);
}
}
);
```
the only exception to that specification is as literal syntax so that
`{__proto__:[]}` is instanceof Array but `{"__proto__":[]}` is not ... that
is the only magic about the property, everything else passes through the
`Object.prototype`
Best Regards
On Mon, May 5, 2014 at 1:36 PM, John Barton <[email protected]> wrote:
> Thanks, Boris, this explanation solves the puzzle for me.
>
>
> On Mon, May 5, 2014 at 1:32 PM, Boris Zbarsky <[email protected]> wrote:
>
>> On 5/5/14, 4:21 PM, John Barton wrote:
>>
>>> Let me rephrase my question: why is the Proxy get even called in this
>>> case?
>>>
>>
>> Because the way __proto__ works is as if the JS implementation had done:
>>
>> (function() {
>> protoGetter = Object.getPrototypeOf;
>> Object.defineProperty(Object.prototype, "__proto__",
>> {
>> set: function() { /* magic here */ },
>> get: function() { return protoGetter(this); }
>> });
>> })();
>>
>> before any page script got to run.
>>
>> Which means that __proto__ is a simple accessor property on
>> Object.prototype. On the one hand, that means that by default it appears
>> on all objects. On the other hand it means it can be shadowed, for example
>> by someone doing an explicit defineProperty for that property name on some
>> object.
>>
>> But it can also be shadowed by proxies, because those get to intercept
>> _all_ property access. So when a obj.__proto__ get happens the
>> implementation walks up the proto chain of "obj" looking for a proxy or an
>> object with an own property named "__proto__". If a proxy is found, its
>> get() is invoked and that's all there is to do as far as the implementation
>> is concerned. If an own property named "__proto__" is found, then the
>> implementation checks whether it's an accessor or value property, and
>> either returns the value or calls the getter, depending on which sort it is.
>>
>> -Boris
>>
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss