Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand instantiated objects in javascript

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to understand the instantiated objects in javascript". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In js, the process of creating an object with a class is usually called instantiation, and instantiating an object is the process of creating an object. "class" is abstract, there is no way to operate it or use its methods and properties, only instantiate this class into an object, you can call a series of its methods and properties; therefore, instantiating an object is a process from abstract to concrete.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

1. What is a constructor?

Constructor is a special method. It is mainly used to initialize the object when it is created, that is, to assign an initial value to the object member variable, which is always used in the statement that creates the object together with the new operator.

This is the Baidu encyclopedia explanation, the explanation is very book-based, but the meaning is still very clear. Let's take a look at a small example:

Var request = new XMLHttpRequest ()

This expression is often used when creating request objects when using AJAX technology. Then we can clearly see that the sentence "new XMLHttpRequest ();" is a standard constructor! We "var" declare a "request" object and use the constructor "new XMLHttpRequest ();" to initialize the "request" object and assign it an initial value. So we know: "the 'function' used with the 'new' operator to create and initialize the object is the constructor."

For example, our common declaration array is the standard constructor: var array = new Array ()

two。 What is an instantiated object

Var request = new XMLHttpRequest ()

In object-oriented programming, the process of creating objects with classes is often referred to as instantiation.

I marked the main points of the explanation in red and blue. To put it bluntly, instantiating an object is the process of creating an object!

So what is "class"? Literally, we can take it as "type". For example, "cake" is a category of desserts, that is, a type, while cheesecake is the specific individual, that is, the object, of the category of cakes in desserts.

We know that in a program language, a "class" is abstract, and we have no way to manipulate it or use its methods and properties. Only by instantiating the class into an object can we call a series of its methods and properties. In fact, this is also very easy to understand, in life abstract things we have no way to see it or capture it, then naturally we have no way to use some of its functions, only the abstract things specific to individual or actual objects, we can clearly understand or understand it; the same is true of programming. Therefore, instantiating an object is a process from abstract to concrete, which is called instantiation.

That's all for "how to understand instantiated objects in javascript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report