I noted some open issues on "Classes with Trait Composition"
Bob Nystrom
rnystrom at google.com
Wed May 18 12:10:24 PDT 2011
On Wed, May 18, 2011 at 11:48 AM, Brendan Eich <brendan at mozilla.com> wrote:
> The whole of class declaration is a mouthful. 'function' and 'prototype'
> are overlong too.
>
Agreed. One of the reasons I'm really excited about this proposal is that it
addresses those:
// old and busted
function SomeClass() {}; SomeClass.prototype.someMethod = function(arg) {
... }
// new hotness
class SomeClass { someMethod(arg) { ... } }
We can try for conciseness in this one corner but it doesn't help in
> general. I think we need to weight the whole syntax and see where the
> verbosity *and other* pain points are in practice.
>
Sure. I'm not stuck on "new", but in the chunks of sample code I've put
together using "constructor" (which is what Traceur uses/did use for a good
while) it did actually stick out as a syntactic wart, at least to me.
Same with 'constructor', and that property must exist somehow. Why not be
> explicit and avoid having two names for one prototype property?
>
> 3 is false in ES5. Reserved identifiers are valid property names. This is
> implemented in all the ES5-supporting browsers.
>
Ah, my mistake. These are both fair points. It's too bad "constructor" is
such a long word.
In the interests of considering all possibilities, one option would be to
use no name at all for the constructor:
class Point {
(x, y) {
this.x = x;
this.y = y;
}
}
I find that simultaneously delightfully lightweight and terrifyingly
obscure.
- bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110518/16c0b49d/attachment.html>
More information about the es-discuss
mailing list