ES6

记录一些工作中遇到ES6相关的知识点

rest参数

ES6 引入 rest 参数(形式为...变量名),用于获取函数的多余参数,这样就不需要使用arguments对象了。rest 参数搭配的变量是一个数组,该变量将多余的参数放入数组中。

1
2
3
4
5
6
7
8
9
10
11
function add(...values) { //[2,5,3]
let sum = 0;

for (var val of values) {
sum += val;
}

return sum;
}

add(2, 5, 3) // 10
1
2
3
4
5
6
7
8
9
10
11
//在查看form-render源码时,发现使用了此种写法来统一接收form、schema等参数
function test({a, ...rest}){
console.log(a)
console.log({...rest}) //{b: 'b', c: 'c'}
}

test({
"a": "a",
"b": "b",
"c": "c"
})

ES6
http://example.com/2023/02/12/ES6/
作者
John Doe
发布于
2023年2月12日
许可协议