首页 > 代码库 > JS 引用

JS 引用

var arr1=[1,2,3,4];
var arr2=arr1;
arr2.push(5);
console.log(arr1);//和arr2一样
console.log(arr1==arr2);//true
console.log(arr1===arr2);//true
function Cat(name){
this.name=name;
}
var p1=new Cat(‘tom‘);
var p2=new Cat(‘tom‘);
console.log(p1==p2);//false
p2=p1;
console.log(p1==p2);//true
p1.name=‘toms‘;
console.log(p2.name);//toms