In JavaScript, the relationship between objects and functions is subtle. They are an "instance" of each other ".
Function instanceof Object and Object instanceof Function are both true
1. We can think that an Object is a special "class", and the "class" here is: Function
So it can be understood as: Object = Function () {} or Object = new Function (); that is, the Object is an instance of the Function. Therefore, the Object prototype chain contains the Function. prototype. prototype. isPrototypeOf (Object) is true
2. In js, all objects (excluding external objects in js language) can be considered as an instance of objects. Function is no exception, Function. prototype is no exception, so Function = new Object (); Function. prototype = new Object (), so Object. prototype. isPrototypeOf (Function) and Object. prototype. isPrototypeOf (Function. prototype) is true
3. Supplement: Function itself is also a "class". However, all "Classes" are Funciton instances, so Function instanceof Function; is true. At the same time, all objects are instances of the Object class, and the Object itself is also an Object. The value of instanceof Object is true for all objects. In addition, it can be considered that the Funciton type is a "derived class" of the Object type. The class Function inherits the class Object and is a "subclass" of the class Object ".