ES6------rest参数
2017-12-23 00:00
218 查看
摘要: 继续~~~~~~
资料源:http://es6.ruanyifeng.com/#docs/function#rest-%E5%8F%82%E6%95%B0
资料源:http://es6.ruanyifeng.com/#docs/function#rest-%E5%8F%82%E6%95%B0
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!--加载 Traceur--> <script type="text/javascript" src="traceur.js"></script> <!--将Traceur文件用于浏览器环境--> <script type="text/javascript" src="BrowerSystem.js"></script> <script type="text/javascript" src="bootstrap.js"></script> <script type="module"> // 1.rest 参数(形式为...变量名),用于获取函数的多余参数 // rest 参数搭配的变量是一个数组,该变量将多余的参数放入数组中。 // 利用 rest 参数,可以向该函数传入任意数目的参数。 function add(...values) { let sum = 0; for(var val of values) { sum += val; } return sum; } console.log(add(1, 2, 3)); // 2.rest 参数代替arguments变量 // arguments function sortNumbers() { return Array.prototype.slice.call(arguments).sort(); } // rest参数 const sortNumbers = (...numbers) => numbers.sort(); console.log(sortNumbers(1, 2)) // 3.rest 参数之后不能再有其他参数(即只能是最后一个参数),否则会报错 function fun(a, ...b, c) { console.log(a) } // 4.函数的length属性,不包括 rest 参数 console.log((function (a) { }).length); console.log((function (...a) { }).length); console.log((function (a, ...b) { }).length) </script> </head> <body> <h1>hello</h1> </body> </html>
相关文章推荐
- ES6中的rest参数与扩展运算符详解
- es6 -- rest 参数
- ES6中的Rest参数和默认参数
- ES6(六: 函数扩展)(默认值,rest参数,扩展运算符)
- es6中的解构赋值、扩展运算符和rest参数使用详解
- ES6-rest参数和扩展运算符
- 在es6中,对rest参数和扩展运算符的理解(待更新)
- ES6-函数的扩展-rest参数
- es6 rest 参数
- ES6-rest参数和扩展运算符
- ES6 rest参数和扩展运算符
- ES6 rest参数和扩展运算符
- ECMAScript6(ES6)标准之函数扩展特性箭头函数、Rest参数及展开操作符
- 【web】Spring RestTemplate提交时设置POST请求参数
- [js高手之路] es6系列教程 - 函数的默认参数详解
- ES6 解构运算符 rest运算符,...运算符
- 探讨JavaScript中的Rest参数和参数默认值
- 对比CodeIgniter的REST_Controller和CI_Controller接收参数,输出的异同
- ES6-变量的结构赋值-函数参数
- Apache Camel rest获取GET请求的参数