Function.create

Claus Reinke claus.reinke at talk21.com
Sun Sep 25 01:35:39 PDT 2011


> It's different when you have syntax:
> -----
> var o = {};
> var a2 = o <| [1, 2, 3];
> -----
> Here, the array syntax literal guarantees (since ES5, not in ES3!) that
> a native array is going to be built. Same goes for "function(){}" or any
> object created with reliable syntax, so the parser can both safely build
> the object and assign the chosen prototype.
>
> That's my interpretation though and i'd be happy to hear from others.

That would seem to call for <| to be a copying operator:

- if RHS is a literal, original object can still be safely updated in place
- if RHS is a non-literal object, a copy of that object is created and
    updated

According to the first point in the proposal comments:

http://wiki.ecmascript.org/doku.php?id=harmony:proto_operator#commentary_and_rationales

the definition of cloning/copying is the show-stopper.

Not sure how that interacts with the RHS function literal special case.
I assume that if we had an accepted short function syntax, that special
case would not even exist. Instead, we'd use:

function(..args) { return (proto <| functionLiteral(..args) ); }

But I'm probably misunderstanding that special case anyway..

Claus
 



More information about the es-discuss mailing list