On Jul 19, 2011, at 4:33 PM, Allen Wirfs-Brock wrote:

> Actually, I'm trying to explore going the other direction.  What would it 
> take to allow object literals to use the same syntax as class declarations 
> for the things that they have in common. 

But why? Even if an object literal is method heavy, the commas are a 
longstanding separator (with a trailing one allowed, finally per ES5, de-facto 
in all but IE during the ES3 period).


>> Method bodies are braced and, like function declarations in ES1-5, do not 
>> require gratuitous ; or , termination or separation from following source 
>> elements.
> 
> but you are not also arguing for eliminating the requirement for a , after a 
> method property in an object.  Right?
> 
> let c = {
>   m1() {...}
>   m2() {...}
>   get g() {...}
>   set g() {...}
>   m3() {...}
> }

No, I've been clear -- I keep saying class body is *not* object literal. This 
cuts both ways!


> If this is correct, I don't see why you are making the argument for one 
> construct and not the other.

Because they are different constructs.

Different semantics should have different syntax. Method shorthand is not a 
strong enough attractor to pull these together.


>> This means data property declarations in a class *do* need some kind of 
>> termination, and the obvious candidate for parallelism with function 
>> declarations is the semicolon.
>> 
>> From this, I concede that data property declarations in a class should not 
>> try to look like property assignments (key: value) in an object literal.
> 
> Object literals and class declarations are very similar in some respects and 
> it seems likely that developers will be refactoring one to the other fairly 
> routinely.

Maybe, but they won't be putting commas after method bodies (including 
constructor) in classes they write fresh.


>  The more different the common elements are the most difficult that 
> refactoring will be.  It also increase, the leaning burden to have different 
> ways to express the same concept that must be used in different contexts.

Sorry, I think making commas optional after methods in object literals is a 
non-goal. I'm not even sure it is unambiguous with the various object literal 
extensions.

/be

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to