它是什么
es6中引入扩展运算符(…),它用于把一个数组转化为用逗号分隔的参数序列,它常用在不定参数个数时的函数调用,数组合并等情形。因为typeScript是es6的超集,所以typeScript也支持扩展运算符。
用在哪儿
可变参数个数的函数调用
function push(array, ...items) { |
更便捷的数组合并
let arr1 = [1,2]; |
替代es5的apply方法
// ES5 的写法 |
求最大值Math.max()
// ES5 的写法 |
通过push函数,将一个数组添加到另一个数组的尾部
// ES5 的写法 |
新建Date类型
// ES5 |
与解构赋值结合,生成新数组
// ES5 |
将字符串转为真正的数组
[...'hello'] |
将实现了 Iterator 接口的对象转为数组
var nodeList = document.querySelectorAll('div'); |
end 2017-02-17 14:46:14