An explicit prototype: prototype
Implicit prototype: __proto__
1. What is an explicit prototype and an implicit prototype?
In JS everything is Object, method (Function) is an object, the prototype of the method (Function.prototype) is an object, the object has an attribute (__proto__) is called an implicit prototype, the object's implicit prototype points to the explicit prototype of the constructor that constructs the object.
A method (Function) is a special object that, in addition to having the __proto__ property as other objects, has a unique prototype property (prototype), which is a pointer to the prototype object. The prototype object also has a property called constructor, which contains a pointer to the original constructor.
Note: Functions constructed by the Function.prototype.bind method do not have a prototype property.
Note: Object.prototype. This object is an exception, and its __proto__ value is null.
2. The relationship between the two
The implicit prototype points to the prototype of the function that created the object
Let's start by looking at how to create an object
A. By the way the object literal.
var person={ name:"Tom"}
B. Create by means of new
// Create a constructor function function Person (name) { this.name=name}// Create an instance of a constructor var person1=new person;
C. Create through Object.creat () mode
But in essence, 3 methods are created by means of new.
One of the objects created by Object.creat (O) is his implicit prototype pointing to O.
Objects created by object literals His implicit prototype points to object.prototype.
constructor function The person is essentially created by the function constructor, which is an instance of the function. The prototype object is essentially created by the object constructor. The built-in function, array number, is also created with a function constructor.
Therefore, it is not difficult to understand the following examples:
// by means of new // true // true // true // built-in functions // true // true
The __proto__ of function points to the prototype of its constructor function;
Object as a constructor (is a function Object!!) Function Object!), so his __proto__ points to Function.prototype;
The __proto__ of Function.prototype points to the prototype of its constructor object;
The __prototype__ of Object.prototype points to null (end);
The connection between explicit prototypes and implicit prototypes in JavaScript