显式参数
未提供隐式参数,参数会默认设置为: undefined
function add (x, y) {console.log(x, y)}add(3, 4); // 3 4add(3); // 3 undefined
隐式参数
JavaScript 函数有个内置的对象 arguments 对象。
function add () {console.log(arguments)console.log(arguments.length)// 解构console.log(...arguments)// let {a, b, c} = arguments; errorlet [a, b, c] = arguments;console.log(a, b, c)}function fn() {}add(3, 4, fn);// [Arguments] { '0': 3, '1': 4, '2': [Function: fn] }// 3// 3 4 [Function: fn]// 3 4 [Function: fn]
arguments 对象
arguments 对象转数组
Array.prototype.slice.call(arguments)// Array.fromArray.from(arguments)// es6 写法[...arguments]
ES6写法reset参数
同上⬆️
function add (a, ...reset) {}
