1. Constructors and instances Suppose you declare a method called function Foo() { console.log("I am a constructor"); } const f1 = new Foo(); Now you can clearly see that 2. Property Prototype Methods are also of object data type, so we can say that a method is an object. Objects have properties, but methods have their own special property called This property will point to a prototype object ( function Foo() { console.log("I am a constructor"); } const f1 = new Foo(); console.log(Foo.prototype); //Foo's prototype object console.log(f1.prototype); //f1 is not underfied 3. Property __proto__ How do instances access shared methods and properties? The f1 instance does not have Foo is the constructor of f1, function Foo() { console.log("I am a constructor"); } const f1 = new Foo(); console.log(Foo.prototype); console.log(f1.__proto__); 4. Accessing methods on prototypes If the Foo constructor wants its instances to have the same properties, such as function Foo() { console.log("I am a method"); } Foo.prototype.name = "I am a property shared by instances created by Foo"; const f1 = new Foo(); const f2 = new Foo(); console.log(f1.name);//I am a shared property of the instance created by Foo console.log(f2.name);//I am a shared property of the instance created by Foo 5. Constructors also have __proto__ It says above that all objects have Then let's find out who is the constructor of Foo. Foo is a function with function-specific methods and properties. Its constructor is Function, a built-in constructor of js. Its So 6. The prototype of the constructor also has __proto__ Whenever we look for 7. Object.prototype is a very special prototype object Constructors such as 8. Summary Only methods, that is, functions, have This is the end of this article about the detailed explanation of JavaScript prototype chain. For more relevant JavaScript prototype chain content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Example code of how to implement pivot table in MySQL/MariaDB
>>: About 3 common packages of rem adaptation
The development of Docker technology provides a m...
Sometimes some docker containers exit after a per...
MySQL Users and Privileges In MySQL, there is a d...
Preface var is a way to declare variables in ES5....
Table of contents 1. Ternary operator judgment 2....
This article example shares the specific code of ...
Table of contents 1. for loop 2. Double for loop ...
Preface The Windows system that can be activated ...
Preface NAT forwarding: Simply put, NAT is the us...
I installed a new version of MySQL (8.0.21) today...
Preface The docker image cannot be deleted. Check...
HTML Design Pattern Study Notes This week I mainl...
This article shares the specific code for JavaScr...
The uniapp applet will have a similar drop-down p...
You can easily input Chinese and get Chinese outp...