ECMAScript(五)rest 参数
rest参数
ES6 引入 rest 参数,用于获取函数的实参,用来代替 arguments
注意:rest 参数非常适合不定个数参数函数的场景
ES5 获取实参的方式
function data() {
console.log(arguments);
}
data('li', 'ab', 'cc');
rest 参数
function data(...args) {
console.log(args);
}
data('白芷', '阿娇', '思慧');
rest 参数必须要放到参数最后
function fn(a, b, ...args) {
console.log(a);
console.log(b);
console.log(args);
}
fn(1, 2, 3, 4, 5, 6);

浙公网安备 33010602011771号