There really is no way out if you chose the class syntax.
The problem is that inheritance in ES6 is done by late initialization of the this with the return value from super() , which is a constructor call, for example, with new . The old "use" idiom ( .call() ) the parent constructor in the current "uninitialized" child instance works no more .
What else you can do is resort to "parasitic inheritance" - you have to explicitly build an instance, expand it and return it:
function MyDerived() { var derived = new MyClass('MyDerived'); β¦
When you do this with new MyClass , you cannot set up the prototype correctly. To do this, you will need to use the new ES6 Reflect.construct function, which takes the child class as an optional third parameter:
function MyDerived() { var derived = Reflect.construct(MyClass, ['MyDerived'], new.target||MyDerived); β¦
This is an added benefit that MyDerived no longer needs to be called with new (if you supply MyDerived when new.target empty).
Bergi
source share