In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about what the js prototype chain is, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
The prototype chain is a mechanism that means that every object in the JavaScript, including the prototype object, has a built-in [[proto]] property that points to the prototype object of the function object that created it, the prototype property.
Function: the existence of prototype chain is mainly to realize the inheritance of objects.
Several concepts about the prototype chain:
1. Function object
In JavaScript, a function is an object.
2. Prototype object
When you define a function object, it contains a predefined property called prototype, which is called the prototype object.
/ / function object function F () {}; console.log (F.prototype)
3 、 _ _ proto__
When JavaScript creates an object, it always has a built-in property of [[proto]] that points to the prototype of the function object that created it. The prototype object also has a [[proto]] property. Therefore, in the constant pointing, the prototype chain is formed.
For example, if we modify the prototype object of object F, we can clearly see the above relationship.
/ / function object function F () {}; F.prototype = {hello: function () {}}; var f = new F (); console.log (f.
4 、 new
When you use new to call the constructor, it is equivalent to executing the
Var o = {}; o.protoprotoplast _ = F.prototypetic F.Call (o)
Therefore, new plays a key role in the implementation of the prototype chain.
5 、 constructor
The prototype object prototype has a predefined constructor property that refers to its function object. This is a circular reference.
Function F () {}; F.prototype.constructor = = F
In practical application, there are often the following ways to write
Function F () {}; F.prototype = {constructor: F, doSomething: function () {}}
The reason for adding constructor here is that if the prototype object is rewritten, the constructor property disappears and needs to be manually fixed.
6. Memory structure of prototype chain
Function F () {this.name = 'zhang';}; var F1 = new F (); var f2 = new F (); this is what the js prototype chain is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.