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
Table of contents 1. Click on the menu to jump 1....
Failure Scenario When calling JDBC to insert emoj...
Preface Every time you use Docker to start a Hado...
I've been playing with the remote development...
Table of contents 1. Compiler code format specifi...
The implementation of expanding and collapsing li...
This article describes how to install the PHP cur...
Ubuntu 16.04 installs the PHP7.0 environment by d...
Table of contents 1. Required attributes 1. name ...
What is HTML? To put it simply: HTML is used to m...
Recently, when I was working on monitoring equipm...
Table of contents How to start mysqld Method 1: m...
It is very common to see images and text displaye...
Table of contents 1. Regular expression creation ...
1. Common connections for mysql INNER JOIN (inner...