es6语法
const arguments = [1,5,6,8,9,10];
const [context, ...rest] = arguments;
console.log(context) // 1
console.log(rest) // [ 5, 6, 8, 9, 10 ]
巧用数组的shift方法
function fn (a,b,c,d) {
let firstArguments = Array.prototype.shift.call(arguments)
console.log(firstArguments) // 1
console.log(arguments) // [Arguments] { '0': 2, '1': 3, '2': 4 }
}
fn(1,2,3,4)
巧用扩展符
类数组也可以使用数组的扩展符使其成为数组
在函数参数中两种方式:
const [first, ...reset] = [...arguments];
[...arguments].slice(1)