On May 18, 2011, at 10:58 AM, Bob Nystrom wrote:
> On Mon, May 16, 2011 at 8:02 AM, Brendan Eich <[email protected]> wrote:
> On May 16, 2011, at 4:54 AM, Dmitry A. Soshnikov wrote:
>> Regarding `new` keyword for the constructor (aka initializer), after all, it
>> als may be OK. E.g. Ruby uses `new` as exactly the method of a class --
>> Array.new, Object.new, etc. Though, `constructor` is also good yeah.
>
> My point is not to bikeshed, rather (a) to name existing prototype properties
> minimally, (b) to avoid preempting other names.
>
> Using "new" for the constructor is one of my favorite feature's of Allen's
> proposal. Things I like about it:
>
> 1. It's terse. Since almost every class defines a ctor, this is helpful.
> "constructor" is a mouthful and repeating the full class name (like in Java,
> C++, etc.) is redundant.
The whole of class declaration is a mouthful. 'function' and 'prototype' are
overlong too. 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.
> 2. I think it's pretty clear to a user what's going on.
Same with 'constructor', and that property must exist somehow. Why not be
explicit and avoid having two names for one prototype property?
> 3. It avoids stealing a valid identifier. You can't define a method named
> "new" but "constructor" is a valid property name.
3 is false in ES5. Reserved identifiers are valid property names. This is
implemented in all the ES5-supporting browsers.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss