Examples of differences between js object creation and js object Creation

Source: Internet
Author: User

Examples of differences between js object creation and js object Creation

A: var obj1 = obj2 = new Object ();

And

B: var obj1 = new Object (),
Obj2 = new Object ();

There are two different assignment methods, which lead to different results. Please pay attention to them ~

A will direct two objects to the same memory address, so that the content of the two objects is consistent.

Var t1 = t2 = new Object (); t1.name = 'hello'; t2.name = 'kakao'; t1.name = null; alert (t2.name); // The result is null.

B Does not.


JS issues with object Creation

You can understand the features of js. When this pointer is used in a function, you need to use the new keyword to obtain its instance. Otherwise, the this pointer cannot find the target.

In addition, js does not have the class syntax at all.

How to create objects in js

.... Objects in js are similar to those in java, but they cannot be constructed simply!
The usage is similar to that of java!

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.