...在函数中使用(函数的参数) 可以当成剩余运算符
展开运算符
let arr = [5,1, 2, 3]; apply 可以改变this执行 第二可以传参 console.log(Math.min(...arr)); function sum(){ console.log(arguments) } function fn(a,b,...args){ // Array.prototyoe.slice.call(arguments,2) sum(...args) } fn('a','b',3,4,5,6,7)
数组的展开和对象的展开
let arr = []; let arr1 = [1,2]; let arr2 = [3,4]; let newArr = arr.concat(arr1,arr2); console.log(newArr); let arr1 = [1,2]; let arr2 = [3,4]; let newArr = [...arr1,...arr2]; console.log(newArr);
展开运算符 可以合并对象和数组
let school = {name:'zfpx',age:9}; let me = {name:'jw',address:'回龙观'} let obj = {...school,...me}; console.log(obj); let result = Object.assign(school,me); console.log(result); // assign和展开运算符可以算是等价的