A basic understanding of __protot__ and Prototype
Prototype – understood as a prototype __proto__ – understood as a link point in the prototype chain
Prototype is an attribute of a function and is essentially an object {}
__proto__ is a property of the Object, which is essentially an Object {}
This is important: the object’s __proto__ is equal to the prototype of the object’s constructor
function Test(){}
const test = new Test()
console.log(test.__proto_ === Test.prototype) //true
Copy the code
Explain the prototype chain in one sentence
A prototype chain is a __proto__ chain based on an instance object up to object.prototype. When you want to get a property in the instance object, you go all the way up the chain.
The particularity of Function and Object
function Test(){}
Copy the code
So let’s first think about what the function Test is constructed from. A) Function B) Function C) Function D) Function
console.log(Test.__proto__ === Function.prototype) // true
Copy the code
Function should also have its own __proto__, and when you print it, you’ll see that it’s special
console.log(Function.__proto__ === Function.prototype) // true
Copy the code
It doesn’t seem reasonable, but it’s something that you’ve been given at the bottom so you can pull something really interesting down here.
console.log(typeof Object); // Function proves that Object is constructed from function
console.log(Object.__proto__ === Function.prototype); // true
console.log(Object.__proto__ === Function.__proto__); // true
Copy the code