剩余参数语法


function(...args){

}

 
function sum(...theArgs) {
  return theArgs.reduce((previous, current) => {
    return previous + current;
  });
}
 
console.log(sum(1, 2, 3));
// expected output: 6
 
console.log(sum(1, 2, 3, 4));
// expected output: 10

  

posted @ 2020-07-26 23:38  Wayhome'  阅读(123)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css