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

Gavin Barraclough barraclough at
Tue Jul 19 18:12:55 PDT 2011

On Jul 19, 2011, at 12:17 PM, Allen Wirfs-Brock wrote:
> One issue is that <| conceptually modifies the [[Prototype]] of its RHS.  As an operator (whether special character or keyword based) we can restrict the RHS to be a literal and define the behavior such that no actual mutation of [[Prototype]] is necessary.
> However, at the value level we have no way to distinguish an object that was created via a literal and which has no references other than the current argument value.  So, when we specify Object.make we have to accept an arbitrary object as the second argument  and specify either [[Prototype]] mutation or some sort of shallow copy, either of which can be problematic. 

On Jul 19, 2011, at 1:27 PM, Brendan Eich wrote:
> We are *not* gonna standardize mutable [[Prototype]].

The concept of an operator that logically modifies the RHS operand seems unfortunate, as does having an operator with an implicit requirement that the RHS be a literal.  The fact that the only reason that setting the prototype is acceptable to us is because the RHS is a literal seems to raise the question whether this really should be the action of an operator?  Do we not just need an extension to the object/array literal syntax to allow the prototype to be specified within the literal?

Some engines already allow syntax to declare a prototype for an object literal, e.g.:

	var o = { __proto__: protoObj, a:1, b:2 };

Does this produce the same results as:

	var o = protoObj <| { a:1, b:2 };

I'm sure that we don't want to standardize __proto__, perhaps an option closer to the spec would be:

	var o = { [[Prototype]]: protoObj, a:1, b:2 };

Though I'm sure this isn't particularly lovable syntax, particularly if we want to support this for array literals.
Maybe something based on the idea of the <| operator might work?, say:

	var o = { |> protoObj, a:1, b:2 };

Apologies in advance if I'm missing an understanding of an important detail of the <| operator as proposed.


More information about the es-discuss mailing list