I just cannot understand, why in object inheritance "instanceof" fails to evaluate "children"-objects as instances of parent prototypes. For example:
function Parent(property) {
this.property = property;
}
function Child(property) {
Parent.call(property);
}
const child = new Child("");
console.log(child instanceof Child); // of course, true
console.log(child instanceof Parent); // false. But why???
As for inheritance of classes (or rather of what is deemed to be classes in JS), the situation is different:
class Parent {
constructor(property) {
this.property = property;
}
}
class Child extends Parent {
constructor(property) {
super(property);
}
}
const child = new Child("");
console.log(child instanceof Child); // true
console.log(child instanceof Parent); // also true!!!
What is the cause of this difference? Is it possible to create children-objects so that they were correctly recognised as instances of their parent prototypes (without resorting to classes)?