第一种:assign方法(浅拷贝)
<script>
let person = {
name:"jack",
age:21,
language: ['java','js','css']
};
let people = Object.assign({},person);
console.log("=======person")
console.log(person)
console.log("=======people")
console.log(people)
</script>
拷贝结果:
第二种:解构表达式(浅拷贝)
<script>
let person = {
name:"jack",
age:21,
language: ['java','js','css']
};
// 拷贝----->将person对象属性值全部拷贝给obj对象,
var {...obj} = person;
console.log("---->person")
console.log(person)
console.log("---->obj")
console.log(obj);
//部分拷贝,将person的name,age以外的属性拷贝给obj2对象
var {name,age,...obj2} = person;
console.log("---->person")
console.log(person)
console.log("---->obj2")
console.log(obj2);
</script>
拷贝后: