ES5 arguments vs ES6 ...rest



ES5 arguments vs ES6 ...rest
"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



​ ​



©xgqfrms 2012-2020



xgqfrms