JS最简单的深浅拷贝

原创 Licking_Dog 随笔 初入前端 112阅读 2019-04-03 21:22:03 举报

//浅拷贝
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 回复