JavaScript 之 arguments 对象

博客转载了关于 Arguments 对象的内容,原文链接为 https://www.cnblogs.com/houfee/p/10911976.html 。

 Arguments 对象

 

function test(arg1, arg2, arg3) {
  console.log(arguments); // arguments类数组对象 Arguments [Array(7), callee...
  console.log(test.length); // 3 形参个数
  console.log(arguments.length); // 7 实参个数
  console.log(arguments.callee); // 指向当前执行的函数 f...

  // 转换为一个真正的Array, 需要接收一下 类数组使用 ... 扩展成真正的 数组
  console.log(...arguments); // 1, 2, 3, 4, 5, 6, 7
  console.log(Object.prototype.toString.call(...arguments)); // [object Number]

  // arguments 对象只能在函数内使用
  console.log(Object.prototype.toString.call(arguments)); // "[object Arguments]"
  console.log(arguments[0], arguments[1]); // 1 2
  console.log(typeof arguments[0]); // number

  // 对参数使用扩展语法
  // 使用Array.from()方法或扩展运算符将参数转换为真实数组: 
  var args = Array.from(arguments);
  console.log(args);
  var args = [...arguments];
  console.log(args);

  // 更改 arguments[1]
  arguments[0] = 666;
  console.log(arguments[0]); // 666

}

let arr = [1, 2, 3, 4, 5, 6, 7]
test(...arr)

 

 

转载于:https://www.cnblogs.com/houfee/p/10911976.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值