xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-02-27 22:53  xgqfrms  阅读(84)  评论(0编辑  收藏  举报