JavaScript中的Rest参数是什么?
休息
ES6带来了rest参数,以简化开发人员的工作。对于参数对象,其余参数由三个点…表示,并在参数之前。为此,将不确定数量的参数设置为数组,它们是Array实例。
示例
让我们看下面的代码片段:
<html>
<body>
<script>
function addition(…numbers) {
var res = 0;
numbers.forEach(function (number) {
res += number;
});
return res;
}
document.write(addition(3));
document.write(addition(5,6,7,8,9));
</script>
</body>
</html>热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话