es6剩余参数...拓展应用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gisdoer/article/details/85123451

查看文章

函数传参

function restParam(a,b,...c){};//b以后所有参数放入c数组中
//c必须为最后一个参数

拓展应用

fn(...[1,2,3])等同于fn(1,2,3)
  • 级联更容易
[1,2,...[3,4,5],6,7]; //1,2,3,4,5,6,7
  • 可迭代对象转为数组
[...document.querySelectorAll('img')];//转为数组
  • 解构时也可用
[a,,...rest]=[1,2,3,4,5];//rest为[3,4,5]
  • 初始化对象时传参毫不费力
new Date(...[2015,31,5])

猜你喜欢

转载自blog.csdn.net/gisdoer/article/details/85123451