An "extend" operator is a natural companion to <|

Axel Rauschmayer axel at rauschma.de
Wed Jul 20 00:51:18 PDT 2011


My opinion can be summarized as follows: The operator is really useful, we need it or at least its functionality (alternatively, as a method). I suspect that the patterns are better supported via class literals that hides the details via sugaring, but they elegantly illustrate why the operator is so useful.

> My think was that the feature could always be extended in the future to allow a non-literal RHS if we wanted to deal with those issues.

Makes sense.

>> From your examples, it looks as if the lhs would be modified, a bit similar to the += operator. Then the "arrow" should probably point in the opposite direction, e.g.:
>> 
>>> objToBeModified +> increment
> 
> I don't follow your logic for the pointer direction. 

True. <& points in the right direction. When I think about it, I actually object to it looking so similar to <| (which is perfect, especially how it looks). This suggests a sameness that does not exist. Compound assignment might be a better idea:

obj += increment; // overloaded for strings, why not for objects?
obj o= increment; // the circle means overriding in many algebraic theories
obj °= increment;

>> I love how the prototype is incremented here. What does "tthis" do? Wouldn't point simply return an object literal (no "this <&")?
> 
> No, because the [[Construct]] internal method set this to a new object whose [[Prototype]] is correctly initialized to Point.prototype.  You could return:
>    Point.prototype <| { ...

Got it. Nice.

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



More information about the es-discuss mailing list