Js constructor function

Isn"t the

h object constructed by the Hero constructor function? How instanceof built-in constructor Object function is also true?

Mar.14,2021

because of prototype inheritance.

h is constructed by the Hero constructor, while Hero inherits from Object , so h instanceof Object is true . And Hero instanceof Object is also true .

clipboard.png

The

instanceof operator is used to determine whether a prototype chain of objects to be detected is an object pointed to by the prototype property of the constructor
all constructor functions are derived from Function.prototype
js everything is an object, and all objects are from Object.prototype


js all objects are from Object.prototype, so all instances are instances of Object

Menu