The prototype chain structure of ordinary objects is described earlier, the properties and methods in the prototype object are introduced, then the prototype chain of the function object is introduced, and the prototype chain is finally integrated.
The properties and methods of the first part Object.prototype
1 Object.prototype.toString method
Because the ToString method is defined in the Object.prototype top-level object, any object has a ToString method.
can be used to detect the type of object, of course, can only detect the type of built-in objects, if it is a custom constructor created by the object can not accurately detect the type.
How to use: Object.prototype.toString.call (object)
Output: "[object constructor name]"
The second value in the result of the final output is the object type that corresponds to the object.
2 Object.prototype.hasOwnProperty ()
Determines whether a property belongs to the object itself, not the inherited property, and the return value is true or false.
All objects can call this method directly.
3 Object.prototype.isPrototypeOf ()
Determines whether the current object is a prototype object of a Parameter object, and returns a value of TRUE or false.
All objects can call this method directly.
4 Object.prototype.propertyIsEnumerable ()
Detects whether this property can be enumerated in an object, returns a value of TRUE or false.
Whether it can be enumerated refers to the ability to access this property through the for...in Loop statement.
The prototype chain of the second part of the function object
The prototype chain of a function object is also based on the object prototype chain.
We can conclude two conclusions:
A any function is an instance of the function constructor (including constructors, such as object, and function itself, which means that you have created yourself): function. __proto__===function.prototype===function.__ proto__
The prototype object of B Function inherits from the prototype object of object: Function.prototype.__proto__===object.prototype
Finally we conclude that Object.prototype is the top-level object for all objects.
The third part of the integration of prototype chain
The concept of prototype chain is abstract, I have drawn a prototype structure here, can be convenient to remember, of course, you can directly use the browser's developer tools to find the prototype chain structure of an object.
Properties and methods of JavaScript prototype objects