Classes: suggestions for improvement

Brendan Eich brendan at mozilla.com
Sun Jun 12 14:38:37 PDT 2011


On Jun 12, 2011, at 2:22 PM, Axel Rauschmayer wrote:

> (1) The syntax for private properties still is a bit clumsy, and @ feels like wasting a nice symbol, how about using private.foo instead of private(this).foo?

No, you need private(other).foo or shorter for things like

 class Point {
   constructor(x, y) {
     private x = x;
     private y = y;
   }
   equals(p) { return private(this).x === private(p).x && private(this).y === private(p).y; }
   ...
 }

BTW, @ is hardly "wasted" as shorthand, since the above is way too long and also requires reifying private data as an object, which we do not want (I mean, I believe no one wants).


> (2) "public" feels superfluous in class body and the word "public" does not really denote the opposite of "static".

Especially when it's not the opposite anyway: "proto" would be better but it is unnecessary.


> (3) Is "static const" possible?

Yes, see 


> This is a bit farther out: There is a use case for having a superclass and 0 or more prototypes at the same time. The former is useful for constructor chaining, the latter could be used to implement poor man’s traits.

This proposal is about prototypal inheritance sugar only. Mark split out the traits stuff for good reason, and we wouldn't want to be poor men (or women) if we could have real traits.


> Does anybody know what Brendan meant in this txjs talk with “Classes made it (Yay, I think? Why am I sad?)”? Is he ambivalent about the proposal? Is there anything he doesn’t like?

You can just ask me ;-).

Something about classes in JS makes me sad, an emotional effect I can't explain fully. In part I fear the "lint brush" aspect I mentioned in the thread Irakli just followed up: class syntax will grow lots of hair over time. In part I think class is the wrong word, as cowboyd tweeted (see below).

Mainly I think we are still finding class syntax, not just the keyword, a bit hard to fit to the prototypal pattern. The super keyword in limited expression forms is no problem. The extends and prototype "Heritage" clause in the class head is ok.

The constructor flows from the prototype-methods-at-class-element-position design, but starts to rankle, if only because of the name's length. As you can see in my posts today, it seems to go downhill from there. And we're still trying to find a better syntax than the "static" keyword.

/be

(I hope this twitter converation is readable.)



cowboyd Charles Lowell 
For the record, I *do* not like the class syntax ES.next either. It's not a class, why would you call it that? #txjs
11 Jun Favorite Retweet Reply

BrendanEich BrendanEich 
@ 
@cowboyd no one could come up with a better name -- we tried. What would you call these things?
11 Jun 
in reply to ↑

@cowboyd
Charles Lowell
@BrendanEich It's a small thing, and I'll get over it, but something about "class" fills me with melancholy.
11 Jun via Twitter for Mac
Favorite Retweet Reply
replies ↓

BrendanEich BrendanEich 
@ 
@cowboyd yeah, me too. Melancholy about classes from a number of people has to matter.
11 Jun 

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


More information about the es-discuss mailing list