I want to extend a class by only adding a new (non static) function, without changing the constructor. My super class can only be constructed from a static function. Now, when I construct my sub class with that static function, I receive an object that is an instance of the super class although I want the sub class. What can I do to achieve what I am looking for without changing the super class?
Here is a minimal example:
class MySuperClass {
static staticConstructor() {
return new MySuperClass()
}
}
class MySubClass extends MySuperClass {
addedFunction() {}
}
const mySuperClass = MySuperClass.staticConstructor()
console.log(mySuperClass instanceof MySuperClass) // true
const mySubClass = MySubClass.staticConstructor()
console.log(mySubClass instanceof MySubClass) // false, I want this to be true
console.log(mySubClass instanceof MySuperClass) // true
// calling mySubClass.addedFunction results in an error due to wrong instance
PS: I could not find a solution here but I am quite sure there should be one. Every search resulted in some DOM manipulation that I am obviously not looking for.