1. PrototypeAll functions in JavaScript have this property, and all objects with a prototype property are functions. The purpose of prototype is to add a method/property to an object. function persistence(){} persion.prototype.name = "xiaoming" console.log(persion.prototype)//{name: "xiaoming", constructor: ƒ} 2. Prototype pointer: __proto__If the above persion function generates an instance object Persion1, and uses prototype to add an attribute to it, the writing is as follows: function persistence(){} persion.prototype.name = "xiaoming" let Persion1 = new Persion(); console.log(Persion1) //The console results are as follows The results of printing instance Persion1 are as follows: From the results printed above, Persion1.__proto__.name = persion.prototype.name, that is, the __proto__ attribute of the instance object is equal to the prototype of its constructor. After understanding the above, the prototype chain is easy to understand. We can directly find the Object method through Persion1.__proto__.__proto__. This may not be very intuitive, here is the code: function persistence(){} persion.prototype.name = "xiaoming" let Persion1 = new Persion(); console.log(Persion1.__proto__.__proto__.toString) //The toString method of Object found through the prototype chain console.log(Object.prototype.toString) //The toString method on Object The console prints the following results, which confirms the level-by-level search feature of the prototype chain. SummarizeAny object can be searched level by level through the prototype chain, that is, the __proto__ attribute. The final focus is Object, and the only way is function. Their relationship is like a chain, and we call this relationship a prototype chain. The above is a brief discussion of the details of JS prototype and prototype chain. For more information about JS prototype and prototype chain, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: In-depth analysis of MySQL execution plans
>>: VMware15 installation of CentOS7 detailed process and common problems (picture and text)
1. Source of the problem A friend @水米田 asked me a...
This article shares with you how to install the M...
The loading speed of a web page is an important in...
As shown below: SELECT prod_name,prod_price FROM ...
Table of contents Tomcat Introduction Tomcat depl...
Table of Contents Introduction Synchronous Asynch...
Table of contents Common array methods concat() M...
1. Best left prefix principle - If multiple colum...
Prerequisite: Mac, zsh installed, mysql downloade...
Table of contents background CommonsChunkPlugin s...
Download and install. First check whether there i...
Ubuntu's own source is from China, so the dow...
When configuring nginx reverse proxy, the slashes...
Table of contents 1.mysqldump Execution process: ...
This article shares the tutorial of MySql install...