Mutable Proto

Nathan Wall nathan.wall at
Mon Mar 18 09:04:40 PDT 2013

A previous thread [1] brought to my attention the fact that objects which don't inherit from Object.prototype won't have mutable __proto__.  This was something I had missed and breaks some scripts I'm currently using because I have objects which I don't want to inherit from Object.prototype but for which I do want to have mutable proto.

Testing in Firefox Nightly I found this workaround:

    var x = { }, y = { foo: 'bar' };

    x.__proto__ = y;
    // => 1 'bar'

    x.__proto__ = null;
    // => 2 undefined

    x.__proto__ = y;
    // => 3 undefined

    var _setPrototype = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set,
        setPrototypeOf =;
    setPrototypeOf(x, y);
    // => 4 'bar'

Is this workaround a temporary bug in Firefox's current implementation? Or will this be the spec'ed behavior for ES6? Can we use such a method to mutate prototype on objects which don't inherit from Object.prototype?


More information about the es-discuss mailing list