js 函数的Arguments 对象 学习

// 严格模式 下
// 剩余参数、默认参数和解构赋值参数的存在不会改变 arguments对象的行为
'use strict'
function func(a) { 
  arguments[0] = 99;   
  console.log(a);// 10
}
func(10); // 10

function foo(...args) {
  return args;
}
foo(1, 2, 3);  // [1,2,3]

/* --------------------------------*/
// 非严格模式
function func(a) { 
  arguments[0] = 99;  // 更新了arguments[0] 同样更新了a 
  console.log(a);// 99
}
func(10); // 99

function func(a) { 
  a = 99;              // 更新了a 同样更新了arguments[0] 
  console.log(arguments[0]);
}
func(10); // 99

function func(a = 55) { 
  arguments[0] = 99; // 没有更新
  console.log(a);//10
}
func(10); // 10

function func(a = 55) { 
  a = 99; // 也没有更新
  console.log(arguments[0]); // 10
}
func(10); // 10

function func(a = 55) { 
  console.log(arguments[0]);
}
func(); // undefined

定义连接字符串的函数

function myConcat(separator) {
  var args = Array.prototype.slice.call(arguments, 1);
  console.log args.join(separator);
}

//  "red, orange, blue"
myConcat(", ", "red", "orange", "blue");
原文地址:https://www.cnblogs.com/xzma/p/8310842.html