+1! It would be great if someone will explain in detail why Object.setPrototypeOf is no go.
We definitely need mutable prototype, but having it via __proto__ really breaks the language. Any function that blindly extends object with provided hash is affected e.g. extend(obj, { __proto__: Error.prototype }). Additionally it means that we need to serialize any user input which eventually may be used as key on a dictionary e.g. data[userDefinedName]. That's bad, and it's hard for me to believe we can't do it better. François REMY-3 wrote: > > I certainly agree, but it has been decided otherwhise by the TC39 members > and I doubt they’re willing to revert their decision. > > > > > > > De : Andrea Giammarchi > Envoyé : 18 mars 2013 17:08 > À : Nathan Wall > Cc : es-discuss@mozilla.org > Objet : Re: Mutable Proto > > > > I would like to see Object.setPrototypeOf(object, proto) too and a > disappeared __proto__ 'till now breaking too much. > > > > It would be much easier to implement all shenanigans via > Object.defineProperty(Object.prototype, '__proto__', {whatever}); rather > than fix current non-standard __proto__ ... > > > > > +1 > > > > > On Mon, Mar 18, 2013 at 9:04 AM, Nathan Wall <nathan.w...@live.com> wrote: > > 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; > console.log(1, x.foo); > // => 1 'bar' > > x.__proto__ = null; > console.log(2, x.foo); > // => 2 undefined > > x.__proto__ = y; > console.log(3, x.foo); > // => 3 undefined > > var _setPrototype = Object.getOwnPropertyDescriptor(Object.prototype, > '__proto__').set, > setPrototypeOf = Function.prototype.call.bind(_setPrototype); > setPrototypeOf(x, y); > console.log(4, x.foo); > // => 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? > > > [1] https://mail.mozilla.org/pipermail/es-discuss/2013-March/029176.html > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > ----- Mariusz Nowak https://github.com/medikoo -- View this message in context: http://old.nabble.com/Mutable-Proto-tp35188550p35196276.html Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com. _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss