Javascript constructor and instantiated object and javascript Constructor

Source: Internet
Author: User

Javascript constructor and instantiated object and javascript Constructor

Preface-- Speak before

Like me, I think many beginners who used to have little experience with background programming languages are confused about a series of "Nouns" in javascript. It seems that I know what I'm talking about, but I still don't know what I actually understand. I want to learn any kind of knowledge, first, we should clarify the most basic terms (knowing what it is about helps us better understand it .) It is helpful for advanced learning. The following is a brief introduction of my understanding of such seemingly unimportant but unclear knowledge points. (If there is any discrepancy, please correct me)

1. What is a constructor?

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

This is an explanation provided by Baidu Baike. It is a book-based explanation, but its meaning is still clear. The following is an example:

Copy codeThe Code is as follows:
Var request = new XMLHttpRequest ();

This expression is often used when a request object is created using AJAX technology. We can clearly see that the phrase "new XMLHttpRequest ();" is a standard constructor! "Var" declares a "request" object, and uses the constructor "new XMLHttpRequest ();" to initialize this "request" object and assign it an initial value. Therefore, we can know that "the 'function' used with the 'new' operator to create an object and initialize the object is a constructor ".

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

2. What is an instantiated object?

Copy codeThe Code is as follows:
Var request = new XMLHttpRequest ();

In object-oriented programming, the process of creating objects using classes is usually called Instantiation.

I marked the emphasis 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 be understood as "type ". For example, "cake" is a dessert classification, that is, a type. Then, the cheese cake is the specific individual of the cake classification in the dessert, that is, the object.

We know that in programming languages, "Classes" are abstract. We cannot operate on them or use its methods and attributes. Only by instantiating this class into an object, we can call a series of methods and properties. In fact, this is quite understandable. We cannot see or capture abstract things in our lives. Naturally, we cannot use some of its functions, only when abstract things are specific to individual, individual, or actual objects can we clearly understand or understand them. The same is true for programming. Therefore, the instantiation object is a process from abstraction to concrete, which is called Instantiation.

The above is all the content of this article. I hope you will like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.