On Thu, Oct 13, 2011 at 4:26 PM, Allen Wirfs-Brock <[email protected]>wrote:
>
> On Oct 13, 2011, at 3:55 PM, John J Barton wrote:
>
> >
> > Suppose for a moment we allowed objects on the RHS:
> > var o3 = p <| o2;
> > Would we imagine that o2 was mutated in any way? I don't think so. Maybe
> there are binary ops that mutate operands, but they don't come to mind. So
> the entire business about mutation of [[ProtoLink]] is not related to my
> interest in allowing object expressions on the RHS of protoLinkSet operator.
>
> Note that my original thoughts that lead to <| included the possibility
> that the RHS could be an arbitrary expression. In order to avoid
> [[Prototype]] mutation that meant that the RHS would have to be shallow
> cloned to produce a new object whose [[Prototype]] was the LHS value. The
> semantics of cloning is not as trivial as somebody seems to assume and the
> primary use case I was trying to address ("subclass" Arrays , Functions, and
> other objects with special implementation level behaviors) didn't require
> it. So it punted and specified that the RHS must be a literal. This left
> open the possibility that at some future date we might want to reconsider
> that restriction.
>
Thank you for this clear background information.
>
> I still haven't found a really compelling use case for a non-literal <| RHS
> and a good definition for object cloning is still a nut to crack. But both
> plausibly might occur.
>
The use case is the same as Object.extend(): the flexible construction of
objects from objects. Object.extend() is used in two ways: 1) To compose
behaviors, and 2) To compose state properties. At present we no simple way
to go from 1 and 2 to 1+2. Instead we have to do a dance with a function
and its .prototype property (or I guess we can mutate __proto__ ;-).
And obviously a good definition of object cloning would be needed for
Object.extend() and it would answer your second objection.
jjb
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss