Spread Operator & Rest parameters
§ 符號是三個點(...) § 一個是用在函式的參數,一個是用在運算中
Rest ( 拿函數多餘的參數 )
let sum = function (a, b, ...number) {} ====> 參數, rest 必須放最後
sum(1, 2, 3, 4, 5); ====> 引數
// a= [1] // b= [2] // numbers= [3, 4, 5]
object
const {x, y, ...z} = {x:1, y:2, a:3, b:4}; ====> 物件解構式
// x= 1 // y= 2 // z= {a:3, b:4}
Spread ( 可擴展在引數任何位置 )
let sum = function (1, 2, 3, 4, 5) {
}
sum(1, ...number, 5); ====> 引數不一定要放在最後
object
const x=1;
const y= {a:3, b:4};
const n = {x, ...y}; ====> n={x:1, a:3, b:4}