NOTES: Proficient in JavaScript----references to objects and objects in JS

Source: Internet
Author: User

/********************************************************************************************************
* Introduction to JS object reference
* Reference is one of the basic JS, the reference is actually a pointer to the actual object location, and the actual object is definitely not a reference.
* objects can have many properties, which can be seen as references to objects to other objects, multiple variables can refer to the same object, and when the object changes, the variable
* Changes will also occur
*
/***************************************** multiple variables referencing the same object **********************************************/
var obj=new Object ();
Obj.oneproperty= ' Warlock ';
var objref=obj;
Alert ("Objref.oneproperty:---" +objref.oneproperty); Output:objRef.oneProperty:---Warlock
Obj.oneproperty= "war";
Alert ("Obj.oneproperty:---" +obj.oneproperty); Output:obj.oneProperty:---War
Alert ("Objref.oneproperty:---" +objref.oneproperty); Output:objRef.oneProperty:---War
You can see that when an object changes, the referenced variable also changes accordingly.
/***************************************** self-modifying object **********************************************/
var items=new Array ("One", "one", "one", "three");
var Itemsref=items;
Items.push ("four");
Alert ("Items:---" +items.length); Output:items:---4
Alert ("Itemsref.length:---" +itemsref.length); Output:itemsRef.length:---4
/***************************************** Modify the application of the object while maintaining integrity ********************************/
var item=new Array ("One", "one", "one");
Itemref=item;
Item=new Array ("One", "one", "one", "three");
Alert ("itemref.length:--" +itemref.length); Output:itemref.length:--2
Alert ("item.length:--" +item.length); Output:item.length:--3
Not pointing to the same reference, item is the new Array ("One", "a", "three"); Itemref is the new Array ("One", "both");
/***************************************** modify the object to generate a new object **********************************************/
var items= "war";
var Itemsref=items;
items+= "Lock";
alert (items); Output:warlock
alert (ITEMSREF); Output:war

NOTES: Proficient in JavaScript----references to objects and objects in JS

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.