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

Bob Nystrom rnystrom at google.com
Wed Jun 8 10:57:33 PDT 2011

On Tue, Jun 7, 2011 at 1:19 PM, Gavin Barraclough <barraclough at apple.com>wrote:

> Ah, good point, I hadn't considered anonymous classes.  Clearly we could
> solve this with a solution specific to these cases (say, "class(){ /*...*/
> }" for anonymous class constructors?), but having mismatching syntax in
> these cases would be a little unfortunate.

That might work, but has the same problem as "new" I believe, where "class"
is a valid property name. It also might be a bit confusing if we later add
support for nested classes.

For what it's worth, I find "constructor" painfully long, but it seems to be
the best solution. I definitely prefer using a single standard token instead
of the class name. I hate having to type the same thing twice, especially if
I'm writing a class WithSomePainfullyLongNameWhichSadlyDoesOccurInPractice.

Just for kicks, here's an even more radical idea: no name at all:

class Monkey {
  () {
    log("I am the monkey's constructor.");

class Point {
  (x, y) { this.x = x; this.y = y; }

It's delightfully terse, but also completely foreign and non-obvious. I'm
90% certain this is a terrible idea.

- bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110608/d1cd2e12/attachment.html>

More information about the es-discuss mailing list