关于arguments参数和形参的问题

传参时,形参固定默认值

        函数中改变此值

                        arguments还是调用时传的实参,跟形参默认值无关,跟函数里修改形参值无关

                        改变的对应参数值在函数中变成了修改的值,不是调用时传的实参,也跟形参默认值无关

        函数中不改变此值

                        arguments得到的是实参数据而不是形参

传参时,形参不固定默认值

        函数中改变此值

                        arguments值随着此值的改变而改变

                        改变的对应参数值在函数中变成了修改的值

        函数中不改变此值

                        arguments得到的是实参数据而不是形参

如果形参在函数调用的时候赋值了,那就会和arguments属性中下标对应的数值相互影响否则不会

形参和实参是映射关系,但是如果用了默认值,那就是映射关系就不存在了,彼此不会影响彼此

arguments的length属性得到的是实参的个数

function(方法名).length是形参个数

function whatever(a, b, c = 5 ) {
//   c=10;
  Cs.log(arguments);
  Cs.log(a,b,c);
 
  //值的准确性校验
  if (a === 1) {
    console.log("The value of a is 1");
  }
  if (b === 1) {
    console.log('The value of b is 2');
  }
  if (c === 3) {
    console.log("The value of c is 3");
  }
 
  if (arguments.length === 5) {
    console.log("We have passed in 5 paramters");
  }
 
  //验证传入的前三个实参与函数的3个形参匹配
  if (arguments[0] === a) {
    console.log('The first argument is assigned to a');
  }
  if (arguments[1] === b) {
    console.log('The second argument is assigned to b');
  }
  if (arguments[2] === c) {
    console.log('The third argument is assigned to c');
  }
  //验证额外的参数可以通过参数arguments获取
  if (arguments[3] === 4) {
    console.log("We can access the fourth argument");
  }
  if (arguments[4] === 5) {
    console.log("We can access the fifth argument");
  }
}
 
//调用函数时传入五个参数
whatever(1,2,3,4,5);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值