Readdition of __proto__

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Oct 15 16:07:10 PDT 2013


not if you parsed that object via `JSON.parse('{"__proto__":[]}')`

in this case is the equivalent of that operation through
`Object.defineProperty({}, '__proto__', {enumerable: true, writable: true,
configurable: true})` so that `obj.__proto__` will result into property
assignment and no setter invoked.

```javascript
var o = JSON.parse('{"__proto__":[]}');

o.__proto__ = Date.prototype;

o instanceof Date;    // false
o.getTime === void 0; // true

delete o.__proto__;   // true

// once again
o.__proto__ = Date.prototype;

// but this time ...
o instanceof Date;    // true
o.getTime;            // function[native]
```

Cheers


On Tue, Oct 15, 2013 at 3:19 PM, Dean Landolt <dean at deanlandolt.com> wrote:

>
>
>
> On Tue, Oct 15, 2013 at 5:50 PM, Brendan Eich <brendan at mozilla.com> wrote:
>
>> Benjamin (Inglor) Gruenbaum wrote:
>>
>>> Not resolving this like o3 (or o6 really) sounds very strange. I think:
>>>
>>> let attr = "__proto__";
>>> let o7 = new Object;
>>> o7[attr] = p; // o7 inherits from p
>>>
>>> Is the correct behavior here (why would it not invoke the setter?)
>>>
>>
>> Allen confirmed, but just to be clear, any world where o["foo"] and do {
>> let key = "foo"; o[key]; } (do-expression syntax from harmony-era strawman)
>> differ is crazytown, and we do not go there.
>>
>
> True, but the __proto__ train left the station bound for crazytown long
> ago...
>
> So just to be clear, the only way to add a __proto__ property to an
> existing object is with Object.defineProperty?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131015/06e24dae/attachment-0001.html>


More information about the es-discuss mailing list