<script type="text/javascript">
//es6中 只能用于数组
//做收集作用
function test(...args){
console.log(args);
}
test(1,2,[3,4]);
//做展开作用
var arr = [1,2,3];
var arr1 = [5,5,5];
console.log([...arr,...arr1]); //相当于concat
console.log([].concat(arr,arr1));
//es7 可用于对象
let company = {
name:'lntu',
age:70
};
let department = {
leader:{
name:'master',
age:70
},
num:80,
}
//是浅层克隆
let obj = {
...company,
...department
}
//是深层克隆(无法深克隆函数、正则等。此时只能用deepclone())
let obj1 = JSON.parse(JSON.stringify({...company,...department}));
console.log(obj,obj1);
</script>