rest 参数
// ES6 引入 rest 参数,用于获取函数的实参,用来代替 arguments// arguments 是一个类数组,本质是对象;而 rest 参数是真正的数据,可以正常调用数组的所有方法。所以在某些应用场景中,无需将 arguments 转为真正的数组,可以直接使用 rest 参数代替// ES5 获取实参的方式// function date() {// console.log(arguments)// }// date('baizhi','shihui')// rest 参数function date(...args) {console.log(args) // filter some every map}date('阿娇','白芷','思慧')// rest 参数必须要放到参数最后function fn(a,b,...args) {console.log(a)console.log(b)console.log('---')console.log(args) // Array(4)}fn(1,2,3,4,5,6)
