I noted some open issues on "Classes with Trait Composition"

Brendan Eich brendan at mozilla.com
Thu May 19 18:41:28 PDT 2011

On May 19, 2011, at 6:34 PM, Brendan Eich wrote:

> On May 19, 2011, at 6:31 PM, Juan Ignacio Dopazo wrote:
>> On a side note, there are a couple of aspects in the "object initializer extension" proposal that I liked a lot and which value I think is being underestimated. The class body similar to an object declaration with commas and colons make it very easy to refactor a class into an object and viceversa. This is not only useful for writing, but it also helps reading because it relates complex objects and classes, which is what we're nowadays doing with the most blogged about pattern in JS, the "module pattern", (function(){ return {} }()) and new function () {}.
>> Is a middle ground possible?
> I tend not to think so (tertium non datur), but initialiser syntax really blows for class bodies when you start mixing in declarations. Declarations want to end with ; or } and never comma after }. So holding to initializer syntax only, and being disciplined about it, might work.

Of course, get/set and now method property initialisers do end in } and then comma (mandatory if not last property in the outer object initialiser, optional if last). That's a bit confusing if anyone is reading these as declarations (function declarations). In C and C++ you learn and avoid }; at end of function, but since empty top-level declarations are allowed (yay C) this doesn't hurt. In JS you can't leave extra commas after braced bodies in other contexts.

If we succeed in standardizing at least the expression-body part of arrow function syntax (which requires restricting label syntax and refactoring the AssignmentExpression-using non-expression-grammar a bit), then short methods and accessors in initialisers, and perhaps class bodies as you propose, won't have the }, eyesore / syntax trap.

I hope this makes sense,


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

More information about the es-discuss mailing list