JavaScript Basics-What is a constructor function? What is an instantiated object?

Source: Internet
Author: User

Preface--Speaking in front

I think there are a lot of beginners who have seldom been in touch with the background programming language before, like me, the confused of a series of "nouns" in JavaScript. Seems to know what to say, but in fact the understanding is not clear; I think, learning any kind of knowledge, the first should be the most basic explanation of the noun clear (know what it is talking about what is, help us understand it better.) It is known that the reason why, so that the future of advanced learning is very helpful. The following is a brief look at my own understanding of such seemingly unimportant but clear knowledge points. (If there is a discrepancy, please correct it)

1. What is a constructor function

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

This is the explanation of Baidu Encyclopedia, the explanation is very book but the meaning of the expression is still very clear. Below is a look at a small example:

var request = new XMLHttpRequest ();

This expression is often used when creating a Request object when using AJAX technology. Then we can see clearly "new XMLHttpRequest", "This sentence is a standard constructor !" our "var" declares a "request" Object , using the constructor "new XMLHttpRequest ();" to initialize the "request" The object assigns an initial value to it. So we can know: "The function that is used to create an object and initialize the object with the ' new ' operator is the constructor."

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

2. What is an instantiated object

var request = new XMLHttpRequest ();

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

I marked the explanation with red and blue above. To be blunt, instantiating an object is the process of creating an object !

So what is " class "? According to the literal understanding we can be understood as " type ". For example " cake ", which is a dessert category , type ; is dessert of this classification of the cake, which is object .

we know that in the programming language, " class " is abstract , we have no way to manipulate it or use its methods and properties, only to instantiate the class as an object, we can call its a series of methods and properties. In fact, this is also very good understanding, in the life of the abstract things we have no way to see it or capture it, then naturally we have no way to use its functions, only the abstract things specific to a single, individual or actual objects, we can clearly understand or know it , programming is also true. Thus, instantiating an object is an abstraction to a specific process, which is called instantiation.

JavaScript Basics-What is a constructor function? What is an instantiated object?

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.