On Sun, Sep 14, 2014 at 10:47 PM, Domenic Denicola < [email protected]> wrote:
> I want to give a +1 to Allen. The syntax really is > what-you-see-is-what-you-get, which is a great virtue. The C++-derived > initializer is cute and tempting, but not nearly as powerful or easy to > grok. > Based on the gists and everything presented in this thread, I'm also +1 here for the same reason Domenic points out. The intention of code that reads: `this = new super();` should be very easily understood, based on my own experience—I was confident in the semantics before I began reading the explanations and rationale. That's not to say that I expect everyone to have the same experience. > > That said, I feel weakly that requiring the correct `this = new > super(...)`and/or `this = Object.create(new^.prototype)` invocation is a > high price to pay for every derived class ever. In particular, "basic > constructor functions" (ES5 "classes") that don't wish to use the > superclass constructor don't need `this = Object.create(new^.prototype)`, > so making ES6 classes require that is strange. It feels like protypal > inheritance has "broken" once you start using ES6 classes, and it requires > you to fix it by manually doing something that was previously implicit. > > I think I'd most be in favor of a third option that implicitly adds `this > = Object.create(new^.prototype)` if no `this`-assignment is present. In ClassDefinitionEvaluation step 2 and 3 ( https://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-classdefinitionevaluation) this is already covered by the semantics for the `extends Superclass` syntax. > That way, the superclass constructor is never implicitly called, which is > kind of what you would expect. Which is how it works in the existing design: class Abstract { constructor() { this.a = "own instance property"; } m() { return "method defined on Abstract.prototype"; } } class Derived extends Abstract { constructor() {} } var d = new Derived(); console.log(typeof d.a === "undefined"); // superclass constructor is never implicitly called console. var d = new Derived(); console.log(typeof d.a === "undefined"); // superclass constructor is never implicitly called console.log(typeof d.m === "function"); // protoParent link is present as expected. This should be extended to subclass definitions with no constructor method: class Derived extends Abstract {} var d = new Derived(); console.log(typeof d.a === "undefined"); // superclass constructor is never implicitly called Rick
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

