var a = new A in JS and the difference from var a = new A ()

Source: Internet
Author: User

The New keyword in JavaScript is completely different from the concept in C#,java.
Example: Var a=new a ();
Let's see what happens with new in JavaScript.
var a={};//set up a new object;
A.__proto__=a.prototype; Point A's prototype to A; Then a inherits the method and properties of a!
A.call (a);//Call the constructor in A;
document.write (A.__proto__===a.prototype);//True
(IE does not support!) Because __proto__ is a private attribute in IE, it cannot be accessed)
So the role of new is actually to build an empty object, and to record the original object's methods and properties through the prototype chain.

So the Var a=new a () is not much different from Var a=new A, they all explain the instructions needed to build the object, such as who the a.__proto__ points to? The name of an empty object? Wait a minute. But one small difference is that if the structure of A is the following:
function A (name,addr) {
This.name=name;
THIS.ADDR=ADDR;
}
Then Var a=new A is not a good object to build.

var a = new A in

JS and the difference from var a = new A ()

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.