JS最简单的深浅拷贝

//浅拷贝
let object = {
name : 'Licking'
};
let object_shallow_copy = Object.assgin(object,{});
object_shallow_copy.name = 'dog';
console.log(object.name);//dog

//深拷贝
let object = {
name : 'Licking'
};
let object_deep_copy = JSON.parse(JSON.stringify(object));
object_deep_copy.name = 'dog';
console.log(object.name);//Licking

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复