For instance :
class Parent {
foo() {
console.log("foo");
}
}
class Child extends Parent {
bar() {
console.log("bar");
}
}
Here, the expression
Object.getPrototypeOf(Child) === Parent
would evaluate to true.
Now I understand the basics of prototypical inheritance and how classes work in Javascript that is, every function has a prototype property, which is copied on to the newly created class instance's __proto__ property upon calling the function with the new operator
I also understand that Object.getPrototypeOf essentially returns the __proto__ property of any given object and generally we simulate inheritance in pure javascript by the means of setting the prototype property of the child class to an instance of the parent class, like this :
function Parent(){}
Parent.prototype.foo = function(){
console.log("foo");
}
function Child(){}
// Inherit properties from Parent
Child.prototype = new Parent();
My questions are :
what does the result of
Object.getPrototypeOfwhen called with a class as an argument represent ? How is it linked to class inheritance in TS/JS ?Is it safe to use
Object.getPrototypeOfto check if whether a particular class extends another class at runtime ?