setPrototypeOf vs obj.__proto__ assignment

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Apr 4 10:49:53 PDT 2014


On Apr 4, 2014, at 10:22 AM, John Barton wrote:

> I was surprised to discover that in chrome at least this is valid:
>   var obj = {};
>   obj.__proto__ = undefined;
> but this throws
>    Object.setPrototypeOf(obj, undefined);
> 
> Is it intended?

Yes,  see the spec at http://people.mozilla.org/~jorendorff/es6-draft.html#sec-set-object.prototype.__proto__ 

It's that way because that's how __proto__ has always worked.

__proto__ is there for legacy compatibility.
setPrototypeOf should be preferred for new code

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140404/bc05461f/attachment.html>


More information about the es-discuss mailing list