1.3 KiB
1.3 KiB
title | localeTitle |
---|---|
Use the Rest Operator with Function Parameters | 将Rest运算符与函数参数一起使用 |
将Rest运算符与函数参数一起使用
休息参数说明
与rest参数相比,Spread运算符
视频解释传播和休息
[### 例
这段代码
const product = (function() {
"use strict";
return function product(n1, n2, n3) {
const args = [n1, n2, n3];
return args.reduce((a, b) => a * b, 1);
};
})();
console.log(product(2, 4, 6));//48
可以这样写
const product = (function() {
"use strict";
return function product(...n) {
return n.reduce((a, b) => a * b, 1);
};
})();
console.log(product(2, 4, 6));//48
```](http://www.youtube.com/watch?feature=player_embedded&v=iLx4ma8ZqvQ
)