/********************************************************************************************************
* 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