Basic concepts
1. Functions can be called by function new, so functions can be referred to as constructors, and the function that is new is called an object.
2, function is a constructor, then there must be a prototype, its prototype is an empty function
3. The prototype object of the function prototype object ultimately points to the Object.prototype
Prototype chain diagram
Prototype chain diagram derived from the above basic concepts
1, the person constructor, since it is a function, then certainly can be created through function, then can be used as an object
2, P object or Function object, the last point is Object.prototype
The relationship between object and function
The relationship is actually more complex, can be detected by the INSTANCEOF keyword
1, the object constructor is instantiated by the function constructor (the object constructor is definitely also a function, since the function is the object, it can be created by the function)
2, function itself is a constructor, since it is also can be created by the functions constructor (this equivalent to create their own)
3, the following returns are true
<Script> //instanceof: Determines whether the prototype of the constructor exists on the prototype chain of the object //function--> Function.prototype----> Object.prototype----> NullConsole.log (FunctioninstanceofObject); //whether the Object.prototype is on the prototype chain of functionConsole.log (FunctioninstanceofFunction);//whether the Function.prototype is on the prototype chain of Function //Object--->function.prototype---->object.prototype----->nullConsole.log (ObjectinstanceofFunction);//whether the Function.prototype is on the prototype chain of objectConsole.log (ObjectinstanceofObject);//whether the Object.prototype is on the prototype chain of Object</Script>
Prototype chain diagram drawn from the above relationship
JS Advanced--function prototype chain