Classes: suggestions for improvement

Brendan Eich brendan at mozilla.com
Tue Jun 14 20:57:09 PDT 2011


On Jun 14, 2011, at 8:51 PM, Breton Slivka wrote:

> Perhaps I am overlooking something obvious, but is there something
> wrong with calling a constructor function `constructor`, rather than
> class or proto or prototype?

Yes, we've been over this in various places, probably need it recorded on the proposal page. 'constructor' is

(1) not reserved, so we cannot support anonymous class expressions written '... constructor {...}' where ... is left expression context;
(2) too long.

Anyway, it's not *just* the constructor that the syntax defines or expresses, as Allen and Bob have pointed out. The prototype properties are the body elements. The constructor function is named 'constructor' on the prototype, based on ES1-5 (user-defined constructor functions each have a .prototype property whose .constructor refers to that function). There are several objects or sets of property or even variable (not yet agreed as being observable as properties -- the private instance variables) defined by one special form.

Starting that form with 'class' is not the worst design, and arguably it remains the best. 'class' is reserved and it has precedent in Smaltalk, Ruby, Python, and other dynamic languages.

/be



More information about the es-discuss mailing list