References in JavaScript (consistent with C)

Source: Internet
Author: User

References in JavaScript (consistent with C)

 

Javascript can be used as an object-orientedProgramming LanguageAnd has the characteristics of object-oriented language.

Here we will talk about the referenced features

 

References can be used in JS to demonstrate the same performance as the C # language.

Instance 1:

VaR obj1 = new object ()

VaR obj2 = obj1;

Obj1.name = "Hello World ";

Alert (obj2.name = obj1.name) // The value is true.

 

Instance 2:

VaR Item1 = new array ('A', 'B', 'C ');

VaR item2 = Item1;

Item1.push ('D ');

Alert (item2.length) // you will find that = 4 is consistent with Item1

 

Instance 3: String instance

VaR str1 = 'hello ';

VaR str2 = str1;

Str1 + = 'World ';

Alert (str2); // It is still hello.

 

The performance in this region is the same as that in C #. Each concatenation or modification of a string object will generate a new object. The original object will be invalid or has no reference.

 

 

 

 

This document uses the unregistered version of blog_backup for export. Please register with soft.pt42.com.

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.