|
导读网页的本质就是超级文本标记语言,通过结合使用其他的Web技术(如:脚本语言、公共网关接口、组件等),可以创造出功能强大的网页。因而,超级文本标记语言是万维网(Web)编程的基础,也就是说万维网是建立... 网页的本质就是超级文本标记语言,通过结合使用其他的Web技术(如:脚本语言、公共网关接口、组件等),可以创造出功能强大的网页。因而,超级文本标记语言是万维网(Web)编程的基础,也就是说万维网是建立在超文本基础之上的。超级文本标记语言之所以称为超文本标记语言,是因为文本中包含了所谓“超级链接”点。 本篇文章给大家带来的内容是关于ES6中剩余参数的代码讲解,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。概述剩余参数将没有对应形参的参数聚合成一个数组 语法function(a, b, ...theArgs) {
}只聚合未对应形参参数剩余参数只会将没有对应形参的参数聚合成一个数组, 而 function add(a, b, ...theArgs) {
return {rest: theArgs, arguments}
}
add()
// {rest: [undefined, undefined, []], arguments: Arguments(0)}
add(1)
// {rest: [1, undefined, []], arguments: Arguments(1)}
add(1, 2)
// {rest: [1, 2, []], arguments: Arguments(2)}
add(1, 2, 3, 4, 5)
// {rest: [1, 2, [3, 4, 5]], arguments: Arguments(5)}剩余参数是数组剩余参数始终是一个数组,而不像 function add(...theArgs) {
console.log(Array.isArray(theArgs))
theArgs.forEach((a)=>console.log(a))
console.log(Array.isArray(arguments))
Array.prototype.slice.call(arguments, add.length).forEach((a)=>console.log(a)) // 转化成数组
}
add(1,2,3) // true 1 2 3 false 1, 2, 3, 4解构剩余参数function add(...[a, b, c]){
return a + b +c
}
add(1, 2, 3) // 6
add(1, 2, 3) // 6使用 |
温馨提示:喜欢本站的话,请收藏一下本站!