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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值