ES5 arguments vs ES6 ...rest params All In One
ES5 arguments vs ES6 ...rest params All In One
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2021-02-27
* @modified
*
* @description
* @augments
* @example
* @solutions
*
* @best_solutions
*
*/
const log = console.log;
function test(obj, ...rest) {
log(`arguments.length =`, arguments.length, arguments);
log(`...rest =`, rest.length, rest);
}
// test();
// arguments.length = 0 [Arguments] {}
// ...rest = 0 []
// test({key: 'value'}, 'a', 'b', 'c');
// arguments.length = 4 [Arguments] { '0': { key: 'value' }, '1': 'a', '2': 'b', '3': 'c' }
// ...rest = 3 [ 'a', 'b', 'c' ]
function func(...rest) {
log(`arguments.length =`, arguments.length, arguments);
log(`...rest =`, rest.length, rest);
}
func();
// arguments.length = 0 [Arguments] {}
// ...rest = 0 []
func({key: 'value'}, 'a', 'b', 'c');
// arguments.length = 4 [Arguments] { '0': { key: 'value' }, '1': 'a', '2': 'b', '3': 'c' }
// ...rest = 4 [ { key: 'value' }, 'a', 'b', 'c' ]
refs
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14457609.html
未经授权禁止转载,违者必究!