I have an old codebase full of subclasses of a some external class, using prototypal inheritance. Recently, this external class has been ported to an ES6 class, but also has new features I'd like to use. Prototypal inheritance doesn't work anymore, and I'm wondering if it's possible to make it work even if it's with some ugly hack. This is basically what I'm trying to do:
class ClassParent {
constructor(a) {
this.a = a;
}
}
var ProtoChildFromClassParent = function(a) {
ClassParent.call(this, a);
}
ProtoChildFromClassParent.prototype = Object.create(ClassParent.prototype);
ProtoChildFromClassParent.prototype.constructor = ProtoChildFromClassParent;
var child = new ProtoChildFromClassParent(4);
console.log(child.a);
I get the following error:
ClassParent.call(this, a);
^
TypeError: Class constructor ClassParent cannot be invoked without 'new'
Please don't post answers like "you should port your subclasses to ES6". I know that's probably the appropriate thing to do, take this question more as a learning exercise / curiosity about JS internals.