In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what is the constructor of javascript, prototype, prototype chain and new", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "what is the constructor of javascript, prototype, prototype chain and new".
1. What is a constructor?
If a function is designed to create an object through the new keyword, it is a constructor.
As follows:
Function Father (name,age) {this.name = name;this.age = age;} function Father (name,age) {this.name = name;this.age = age;}
The constructor has the following characteristics:
(1) uppercase initials
(2) the constructor should be called using new
(3) after the constructor is called, an object is returned
(4) the return value of the constructor
If the returned value is a number, string, Boolean, ignore it directly, it is considered invisible.
If the returned value is an object, the returned object is used
(5) this in the constructor
When you use this in the constructor, it refers to the newly created object
2. How to create an object through the constructor?
With new, this process is also called instantiation, as follows:
Const let = new Father ('jhony',34); 3. What happens to the process of new an object?
Create a new object in memory {} bind the _ proto_ of the new object (chorme has been changed to [[Prototype]]) to the prototype of the constructor to bind the this to the new object fn.apply (obj,this) add properties to the new object if the constructor returns a non-empty object, return the new object you just created
The [[prototype]] attribute is hidden, but most current new browser implementations are represented using _ _ proto__. We can explicitly access the prototype property of the constructor.
4. What is the prototype?
Father.prototype is a prototype, it is an object, we also call it a prototype object.
Prototypes can share methods, and the this in the prototype points to the instance.
For example, Father.protoype.getAge can share a method without opening up a separate space.
5. The relationship between prototype, constructor and instance?
The implicit prototype of Object.prototype, that is, Object.prototype._proto_ ultimately points to null
Several formulas:
Object.__proto__ = = Function.prototype;Function.prototype.__proto__ = = Object.prototype;Object.prototype.__proto__ = = null;6, what is the prototype chain?
The object can look for a method based on the _ _ proto__ property until it finds or finds the top level. The _ _ proto__ that this process depends on is called the prototype chain (poof-- your own saliva translation).
7. Class?
Class is a grammatical sugar, just another way to write a constructor.
The above is about the content of this article on "what are the constructors, prototypes, prototype chains and new of javascript?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.