new instantiation design alternatives

Domenic Denicola domenic at domenicdenicola.com
Thu Sep 18 13:11:21 PDT 2014


From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Domenic Denicola

> 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.

Actually, this is a really important point. Since HTMLElement is abstract (throws on construct in all cases), the *only* way of extending it is by doing `this = Object.create(new^.prototype)`. You *cannot* extend it with `this = new super()`, either implicitly or explicitly, since `new super()` throws.

So if you want to extend HTMLElement, you will need `this = Object.create(new^.prototype)`, either implicitly or explicitly. (And I argue for implicitly.)


More information about the es-discuss mailing list