Harmony object literals

Brendan Eich brendan at mozilla.com
Mon Jun 6 09:48:24 PDT 2011

On Jun 6, 2011, at 9:38 AM, Kam Kasravi wrote:

> I see, the object's prototype is to the left of <| and the actual object is to the right. I guess that was made clear in the proposal though I suspect others will invert the relationship since javascript programmers are used to defining the prototype after defining the object.

"... after defining the constructor", you mean? Because with object initialisers that preset __proto__, programmers definitely create prototype before delegating object.

> The <| operator seems like you're piping something into a target rather than the other way around, you know like the shell < operator. Thanks for the clarifications.

The exact syntax is still being fine-tuned and perhaps even debated.


> On Jun 6, 2011, at 7:57 AM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> On Jun 6, 2011, at 2:31 AM, Kam Kasravi wrote:
>>> In the object literals proposal the following 2 examples are given below:
>>> var enhancedArrayProto = Array.prototype <| {
>>>       do (func) {return this.foreach(func)},
>>>       search (key {return this.indexOf(key) >= 0}
>>>   };
>>>   var myArray = enhancedArrayProto <| [0,1,2,3,4,5];
>>> 1. I believe search is missing a ')'
>> yes
>>> 2. The first example is adding another prototype to Array.prototype, eg Array.prototype.prototype that contains do and search. Since this appends to the proto chain is it correct to say it's not possible to override methods using this operator? That is it's effect should only be additive?
>> It is creating a new object whose [[Prototype]] is Array.prototype. If this new object is used as a prototype it will provide all of the inherited Array.prototype methods plus do and search.  The new object could over-ride properties defined by Array.prototype but in this example it does not.
>>> 3. Since the <| operator accepts an ObjectLiteral would it be extended to include classes?
>> Yet to be determined. Whether it is useful/meaningful will depends upon how constructor inheritance is defined via the class declaration.
>>>   var enhancedArrayProto = Array.prototype <| class {
>>>       public do (func) {return this.foreach(func)}
>>>       public search (key) {return this.indexOf(key) >= 0}
>>>   };
>>> 4. I'm not quite clear on what the myArray example does, is it adding a new prototype that provides initialization of some kind?  
>> It is just creating a new array object whose immediate [[Prototype]] is enhancedArrayProto.  The new object has all all of the special array functionality. 
>> Allen
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110606/a078baca/attachment-0001.html>

More information about the es-discuss mailing list