Classes: suggestions for improvement

Brendan Eich brendan at mozilla.com
Sun Jun 12 14:55:38 PDT 2011


On Jun 12, 2011, at 2:22 PM, Axel Rauschmayer wrote:

> I really like the proposal: it is very lightweight syntactic sugar. For example, it is not that radically different from Resig’s Simple Inheritance (whose "look" I like).

There is good in the proposal, don't get me wrong. I worked on it at the end, because I believe developers want sugar for the prototypal pattern, they've said so often.


> The "super" keyword for calling overridden methods and chaining super-constructors

Yes, this is good but somewhat separable from class {...}, although we need a context in which "super" makes sense as a special form.


> and the "static" keyword for defining class properties are welcome additions.

Why "static" is the wrong word: there is nothing compile-time about the class properties. Classes are expressible (anonymous, even), as well as declarable in nested (generative) ways.

Using "class" does not work if one wants nested classes, although the default that binds prototype properties for ExportableDefinitions including Declarations seems like exactly the wrong default: how often do you want class Outer { class Nested {} ... } to make Nested a property of Outer.prototype, instead of a class property (Outer.Nested)?

Again, the grammatical retasking of certain Declarations to bind prototype properties (instead of lexical bindings in the class body, or perhaps class properties -- but perhaps not) seems like a mistake.

/be



More information about the es-discuss mailing list