The reasons for doing this are complicated, but it boils down to flow not understanding mixins or any other way of modifying an ES6 class's prototype. So I'm falling back to ES5, but I can't figure out how to call the constructor of an ES6 class without new
:
class A {
constructor() {}
}
function B() {
// what do I put here? I would do something like
// A.prototype.constructor.call(this) but that throws an error saying the
// constructor can only be called with `new`
}
B.prototype = Object.create(A.prototype);
Answering this myself:
class A {
constructor() {}
}
function B() {
Object.assign(this, new A());
}
B.prototype = Object.create(A.prototype);
Not sure if there are any side-effects here or not
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With