On Thu, Sep 18, 2014 at 10:06 PM, Domenic Denicola < dome...@domenicdenicola.com> wrote:
> From: dslo...@google.com [mailto:dslo...@google.com] On Behalf Of Dmitry > Lomov > > > I am not sure what do you mean by "abstract" class here. > > I'm just quoting Allen's gist. It's a base class whose constructor always > throws (in the gist, by doing `this = undefined`). Almost all DOM classes > are currently like this, for example. > Got it. > > > I think "the Dominic alternative" is problematic in that it makes it > easy to forget to call base constructor. In majority of the cases you > really want to do it, and implicit "this = Objec.create(new^.prototype)" > will do the wrong thing without warning you. > > My argument for it is that it works exactly like normal function-based > inheritance works today. That is: > > ```js > function Base() { } > Base.prototype.foo = function () { }; > > function Derived() { > // note: no Base.call(this) > } > Derived.prototype = Object.create(Base.prototype); > > var d = new Derived(); > assert(typeof d.foo === "function"); > ``` > > Despite omitting the `Base.call(this)`, which is analogous to omitting > `this = new super()`, I still have a correctly set-up prototype linkage. I > would prefer if the following ES6 code: > > ```js > class Base { foo() { } } > > class Derived extends Base { > constructor() { /* note: no this = new super() */ } > } > > var d = new Derived(); > assert(typeof d.foo === "function"); > ``` > > also had the assertion pass. With alternative 1 (no implicit super; no > implicit `this = Object.create(new^.prototype)`), the assertion will fail, > as the prototype linkage will be incorrect. > Note that in "no explicit constructor invocation" case you will fail earlier (on return from Derived constructor), and this is an early error.
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss