why not "new" instead of "constructor"?

Brendan Eich brendan at mozilla.com
Sat Nov 19 15:14:34 PST 2011


On Nov 19, 2011, at 2:58 PM, Axel Rauschmayer wrote:

>>> I like the idea of replacing the method name “constructor” with something better, but “new” suggests instantiation *and* initialization to me. Is “init” a possibility?
>> 
>> Who said anything about "replacing"?
>> 
>> If we are trying to match or sugar the prototypal pattern, then whatever the constructor name or keyword in the syntax, there must be for class C a back-link C.prototype.constructor.
> 
> 
> I only meant replacing in as far as the method that was previously called “constructor” is now called “new” in Allen’s example:
> 
> let Point = class {
>   x: 0,  //not really needed unless defining an object exemplar 
>   y: 0, 
>   new(x,y) {
>      this.x = x;
>      this.y=y;
>   }
> };
> 



That's the point: it's not just a method. It is a special form. In classes as proposed where the name was 'constructor', or if it's 'new' as in Dave's http://wiki.ecmascript.org/doku.php?id=strawman:minimal_classes proposal. It is not just another method that happens to have a catchy name.

/be



More information about the es-discuss mailing list