On Thu, Oct 13, 2011 at 3:13 PM, John J Barton <[email protected]>wrote:
> > > On Thu, Oct 13, 2011 at 11:51 AM, Brendan Eich <[email protected]>wrote: > >> On Oct 13, 2011, at 2:19 PM, John J Barton wrote: >> >> On Thu, Oct 13, 2011 at 10:29 AM, Brendan Eich <[email protected]>wrote: >> >>> On Oct 13, 2011, at 1:17 PM, Brendan Eich wrote: >>> >>> ... >> >>> Object.getPrototypeOf is the "get" API in ES5. For the "preset" API we >>> want syntax at least, to avoid copying literals passed to a functional API. >>> We could have the functional API too but it differs in making a copy of >>> whatever object is passed in as the "RHS", as Jake just wrote. It would not >>> be Object.setPrototypeOf. >>> >>> I guess this is a performance argument? (I don't buy then) >> >> >> No, the semantics observably differ. Object.setPrototypeOf follows the >> "set" convention that suggests it mutates the [[Prototype]] of its first >> parameter, but TC39 won't agree to mutate existing objects' [[Prototype]] >> internal property values, even though many engines support that via writable >> __proto__. >> > > (Sorry, I misplaced my comment, I have none about setPrototypeOf) > >> >> So let's say we call the function Object.make. Then consider: >> >> let o1 = {q: 99}; >> let o2 = Object.make({p: 27}, o1); >> assert(o2 !== o1); >> o2.q = 100; >> assert(o1.q === 99); >> >> That's not how <| works. >> > > Darn, now I'm lost again. I would have said "That's how <| works" :-( > I would have said > o2 = {p:27} <| o1; // aka Object.make() > o2 is {q:99, [[ProtoLink]]: {p:27}} so > o2 !== o1 true > o2.q = 100; > o2 is now {q:100, [[ProtoLink]]:{p:27}} > o1.q === 99 true, but irrelevant > Obviously I've misunderstood something. > Simply stated, the triangle operator lets you set the prototype of an object if and only if that object has not yet been observably instantiated. It's a small tradeoff, but it gives us many of the benefits of mutable protos without the known hazards.
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

