根据mdn的解释 the spread syntax allows an expresstion to be expanded in palces where mutiple arguments (for function calls)or multiple elements (for array literals) or multiple variables (for destrucring assignment) are expected
1.在函数调用时用来展开数组到函数的参数
例子:
function add(a, b, c,d) { console.log(a + b + c+d)}var nums = [34, 21, 2,2]add(...nums)//console output 49
2.展开数组到一个数组元素
var fruits=['apple','pea','cherry']var foods=['rice',...fruits,'mellon','noddles']console.log(foods)//output in command line ['rice','apple','pea','cherry','mellon','noddles']
3.展开对象到一个对象内的属性(stage 3 draft ,has not been supported util right now)
let obj = { name: 'Ajaxyz', age: 25}let objClone = { gend: "male", ...obj}console.log(objClone)