This is related to an old question but I'm specifically asking about extending a new ES6 class using the old way of writing a function.
The following code doesn't work.
class X {
a;
constructor(a) {
this.a = a;
}
}
X.call({}, 3); // Uncaught TypeError: Class constructor X cannot be invoked without 'new'
Is there a way to indirectly call the constructor function? For example, is it possible for me to use the old-fashioned prototypical inheritance to make a Y?
function Y(a) {
X.call(this, a); // this doesn't work here, can't use super as well
}
Y.prototype = Object.create(X.prototype);
Object.setPrototypeOf(Y, X);
const y = new Y(12);