var obj1 = {
'name' : 'zhangsan',
'age' : '18',
'language' : [1,[2,3],[4,5]],
};
var obj2=obj1;
obj2.name = "lisi";
obj2.language[1] = ["二","三"];
console.log('obj1',obj1) //obj1,{"name":"lisi","age":"18","language":[1,["二","三"],[4,5]]}
console.log('obj2',obj2) //obj2,{"name":"lisi","age":"18","language":[1,["二","三"],[4,5]]}
// 浅拷贝
var obj1 = {
'name' : 'zhangsan',
'age' : '18',
'language' : [1,[2,3],[4,5]],
};
var obj3 = shallowCopy(obj1);
obj3.name = "lisi";
obj3.language[1] = ["二","三"];
function shallowCopy(src) {
var dst = {};
for (var prop in src) {
if (src.hasOwnProperty(prop)) {
//console.log(src)
// console.log(prop)
// console.log(src.hasOwnProperty(prop))
dst[prop] = src[prop];
}
}
console.log(dst)
return dst;
}
console.log('obj1',obj1) //obj1,{"name":"zhangsan","age":"18","language":[1,["二","三"],[4,5]]}
console.log('obj3',obj3) //obj3,{"name":"lisi","age":"18","language":[1,["二","三"],[4,5]]}
console