Spread / Rest

Spread / Rest (分散 / 其餘)

Spread

function yo(x, y, z){
  console.log(x, y, z);
}

yo(...[1, 2, 3]);

Rest

  • 只能用在最後一個參數
function yo(...val){
  console.log(val);
}

yo(1, 2, 3);
function yo(greeting, ...val){
  console.log(greeting);
  console.log(val);
}

yo('hi', 1, 2, 3);

results for ""

    No results matching ""