📜  无限的可选参数 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:01.438000             🧑  作者: Mango

代码示例1
// arguments is "like" an array that stores all arguments given to manyArgs
// (User can invoke manyArgs with arguments even though none are specified)
function manyArgs() {
  for (var i = 0; i < arguments.length; ++i)
    alert(arguments[i]);
}
// Note: for arrow functions you must do
let manyArgs = (concreteArg1, concreteArg2, ...rest) => {
  for (var i = 0; i < rest.length; ++i)
    alert(rest[i]);
      // concreteArgs are not included in rest "array"
}