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)
Scenario You need to use the xshell tool to conne...
1. Install components yum install epel-rpm-macros...
Disable swap If the server is running a database ...
Example: We use the Python code loop_hello.py as ...
Table of contents Overview Create a type definiti...
As a lightweight open source database, MySQL is w...
Environment Introduction: Ubuntu Server 16.04.2+M...
Input subsystem framework The linux input subsyst...
Based on the Vue image magnifier component packag...
The default ssh port number of Linux servers is g...
<br />The countless information on the Inter...
The shutdown.bat file has a sentence if not "...
Or write down the installation process yourself! ...
If a form field in a form is set to disabled, the ...
Create a table CREATE TABLE `map` ( `id` int(11) ...