How to understand the relationship between Object and Function in javascript?

how to understand the relationship between Object and Function in javascript? Can the prototype chain explain the logic of the following two statements?

Object instanceof Function  //true
Function instanceof Object  //true

Oct.16,2021

everything is an object. Object is originally a class, and a class is also a function


take a closer look at this series, and you should understand it after reading it.

in-depth understanding of javascript prototypes and closures (closure)
http://www.cnblogs.com/wangfu.


once explored and wrote an article (the quality is not too high. ), I've almost forgotten it now. If you're interested, you can have a look at it.

an exploration of prototype chains

attach a picture in the article:

The question of

has been answered very thoroughly. The landlord can take a look at the question of
js prototype. What is the relationship between Object and Function?


1. First of all, the inherited body is actually the prototype of the constructor
2, and then

The
instanceof operator is used to test whether the prototype property of the constructor appears anywhere in the object's prototype chain-- from MDN

that is, as long as the prototype of a constructor, that is, the prototype has appeared in the prototype chain, instanceof will return true;
3, whether it is Object, Function or Array, they are all constructors in essence, so they inherit from Function.prototype, that is, Function.prototype appears in the prototype chain, so
Function instanceof Function / / true
Object instanceof Function / / true
4. We continue to search along the prototype chain. Function.prototype is essentially an object, which inherits from Object.prototype, that is, Object.prototype, which also appears in the prototype chain. So
Function instanceof Object / / true
Object instanceof Object / / true

Menu