Finding a "safety syntax" for classes

Brendan Eich brendan at mozilla.org
Fri Mar 23 10:27:39 PDT 2012


Yet didn't we go over this previously?

https://mail.mozilla.org/pipermail/es-discuss/2011-June/015014.html 
(from you ;-)

in reply to

https://mail.mozilla.org/pipermail/es-discuss/2011-June/015012.html 
(from Bob Nystrom)

It's also a bit novel to preempt the class name in its own prototype, 
but usually ok. Any of {constructor, new, <classname>} is a special form 
as noted. It's true that 'constructor' avoids collision but OTOH, it's 
overlong. None of these names avoids magic wiring behind the scene.

Someone on twitter pointed out that class name minifies well, but so 
does constructor, and anyway transport-encoding compression makes this moot.

Anonymous classes are an important use case IMHO, to match anonymous 
functions and the prototypal pattern.

/be


Gavin Barraclough wrote:
> On Mar 23, 2012, at 12:42 AM, Claus Reinke wrote:
>
>> - would it make sense to name the constructor after the class
>>   (avoiding 'constructor' and 'new')?
>
> I was about to suggest exactly the same thing.
>
> If I see a line of code saying
>     let x = new FooBar();
> and want to understand what it does, I'm instinctively looking for a 
> function named FooBar, not one named either 'new' or 'constructor'.
>
> Between 'new' and 'constructor', new seems like the better choice to 
> me.  Whilst it is true that prototypes currently contain a constructor 
> property, I don't see a lot of code that explicitly accesses this.  In 
> terms of the language actually actively in use in scripts by ES 
> programmers, 'new' is currently in the common lexicon, and 
> 'constructor' doesn't seem to be.  [ I make this statement on casual 
> observation rather than any empirical evidence. :-) ]
>
> cheers,
> G.
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list