本文主要记录在使用Vue开发前端页面时,遇到的前端ES知识点整理.
1: ...(三个点) 运算符
合并数组,
合并数组时与ES5的 concat方法一致
var list=[1,2,23,4] undefined var a=list[0] undefined a 1 rest=list.slice(1) (3) [2, 23, 4] [a,...rest] (4) [1, 2, 23, 4]
当合并obj对象时,将对象作为数组0,继续组合...b的数组
var a={} undefined b (4) [1, 2, 3, 4] [a,...b] (5) [{…}, 1, 2, 3, 4] 0: {} 1: 1 2: 2 3: 3 4: 4 length: 5 __proto__: Array(0)
...如果用于数组赋值,则必须放到最后
如以下会报错
如果将扩展运算符用于数组赋值,只能放在参数的最后一位,否则会报错
const [...butLast, last] = [1, 2, 3, 4, 5];
const [first, ...middle, last] = [1, 2, 3, 4, 5];
用于字符串时,表示将字符串拆分
[...'helloword'] (9) ["h", "e", "l", "l", "o", "w", "o", "r", "d"] 0: "h" 1: "e" 2: "l" 3: "l" 4: "o" 5: "w" 6: "o" 7: "r" 8: "d" length: 9 __proto__: Array(0)
用于Map
let map=new Map([[1,'one','two']]); undefined map Map(1) {1 => "one"} map[0] undefined map.1 VM1641:1 Uncaught SyntaxError: Unexpected number map Map(1) {1 => "one"}[[Entries]]0: {1 => "one"}size: (...)__proto__: Map map.keys() MapIterator {1}[[Entries]]0: 1__proto__: Map Iterator[[IteratorHasMore]]: true[[IteratorIndex]]: 0[[IteratorKind]]: "keys" [...nap.keys()] VM1757:1 Uncaught ReferenceError: nap is not defined at <anonymous>:1:1 (anonymous) @ VM1757:1 [...map.keys()] [1]