Any reason why __proto__ is not a well known symbol?

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Feb 16 08:30:53 UTC 2016


`Object.getPrototypeOf` and `Object.setPrototypeOf` works everywhere,
including null objects, as long as extension hasn't been prevented (
`Objet.freeze`, `Object.seal` or `Object.preventExtension` )

It's `__proto__` accessor that indeed doesn't work as expected in null
object, where it's always stored as key.

```js
var dict = Object.create(null);
dict.__proto__ = [];

Object.keys(dict); // ["__proto__"]
dict instanceof Array; // false

Object.setPrototypeOf(dict, []);
dict instanceof Array; // true
```

However, if you want the key `"__proto__"` you can specify it at string at
runtime `{"__proto__": "this way"}` or use `Object.defineProperty(obj,
"__proto__", {value: "any"})`

Regards



On Tue, Feb 16, 2016 at 5:47 AM, JD Isaacks <jd at jisaacks.com> wrote:

> > Object.getPrototypeOf and Object.setPrototypeOf are the "no-dunder"
> ways to do it.
>
> Not if you are trying to set in an object literal.
>
> On Tue, Feb 16, 2016 at 12:17 AM, Kevin Smith <zenparsing at gmail.com>
> wrote:
>
>> Is there a migration to make it a Symbol in ES7?  (ignorant question?)
>>>
>>
>> Object.getPrototypeOf and Object.setPrototypeOf are the "no-dunder" ways
>> to do it.
>>
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160216/6a53de62/attachment.html>


More information about the es-discuss mailing list