New issue
Advanced search Search tips

Issue 2727 link

Starred by 3 users

Issue metadata

Status: WorkingAsIntended
Owner: ----
Closed: Apr 2015
HW: ----
NextAction: ----
OS: ----
Priority: ----
Type: ----

Sign in to add a comment

changing prototype chain using __proto__ fails

Reported by, Jun 12 2013

Issue description

function foo() {}
var proto1 = Object.create(null, {}) 
proto1.value= 101;

var proto2 = Object.create(proto1, {}) 
foo.prototype = proto2;

o = new foo();
assertTrue(o.value == 101);
proto2.__proto__ = null;
assertTrue(o.value == undefined);

The above test fails at last step.
Version: latest BE

Comment 1 by, Jun 17 2013

This behavior is correct per the ES6 spec of __proto__. Prior to ES6 browsers behaved so differently on the edge cases, that there was no de facto agreement on such matters. In ES6, Object.prototype.__proto__ is an accessor property whose setter changes the [[Prototype]] of its "this". The proto1 object above does not inherit from Object.prototype, so neither do any of the objects that inherit from it. The __proto__ assign is therefore not intercepted by that setter, and so simply creates a normal property that happens to be named "__proto__".

I suggest closing this out as Invalid or WorkingAsIntended.

Comment 2 by, Jun 30 2013

The solution is to use Object.setPrototypeOf (which is not yet implemented)
Status: WorkingAsIntended
As explained in comment #1, this is working as intended according to the ES6 spec draft (the first version of the spec that actually defines __proto__ behavior).

Sign in to add a comment