学无先后,达者为师

网站首页 编程语言 正文

arguments获取当前所在函数

作者:Wxinin 更新时间: 2022-04-23 编程语言

arguments是存在AO中的类数组对象
可以使用length和index
但是不能使用数组的一些方法,比如forEach、map

function foo(num1, num2, num3) {
  // 类数组对象中(长的像是一个数组, 本质上是一个对象): arguments
  // callee获取当前arguments所在的函数
  console.log(arguments.callee)//foo(){}
  // arguments.callee()---这样写会递归
}

如何将arguments转化成数组类型

1.for循环遍历arguments
2.

Array.prototype.slice将arguments转成array
  var newArr2 = Array.prototype.slice.call(arguments)
  console.log(newArr2)

原文链接:https://blog.csdn.net/weixin_44283589/article/details/123733560

栏目分类
最近更新