arguments并不属于很偏的一个知识点,但我之前一直以为它是一个以实参为元素的数组。实际上arguments并不是一个数组,而是一个只具有length属性的类数组,数组的其它方法它都不具备。可以通过.call()执行silce方法它转换为数组。 argument有一个重要的参数callee指向当前执行的函数本身,也就是说们通过它可以递归执行函数。 例如,使用setTimeout来实现setInterval,可以这样写:

setTimeout(function(){//do somethingsetTimeout(arguments.callee,200);
},200);复制代码

同时,callee也可以接收参数:

function add(){let num = arguments[0]num++console.log(num)if(num<10){arguments.callee(num)}
}
add(0)//1,2,3,4,...,10
复制代码

caller则是指向当前运行函数的调用者:

function handleAdd(){let num = arguments[0]add = function (){num ++console.log(num)console.log(arguments.callee.caller)//function handlerAddconsole.log(arguments.callee.caller==add.caller)//true
}add()
}
handleAdd(0)
复制代码

转载于:https://juejin.im/post/5cbb1c9e6fb9a0688f376776

关于arguments相关推荐

  1. JavaScript arguments对象

    1.在JavaScript中,arguments对象是比较特别的一个对象,实际上是当前函数的一个内置属性.arguments非常类似Array,但实际上又不是一个Array实例.可以通过如下代码得以证 ...

  2. 【Qt】Qt再学习(十六):QObject::connect: Cannot queue arguments of type ‘QString‘

    1.问题描述 跨线程使用信号和槽时,如果是非const的引用传参,就会报如下的错误: QObject::connect: Cannot queue arguments of type 'QString ...

  3. java unlimited_具有无限参数的Java方法(Java method with unlimited arguments)

    具有无限参数的Java方法(Java method with unlimited arguments) Spring框架使用方法,您可以根据需要传递尽可能多的参数. 我想写一个函数,也可以采取无限量的 ...

  4. javascript函数嵌套时arguments的问题

    疑问: var funtest = function () {var fun = function (val, val2) {alert(arguments.length); //此处答案? 有些人回 ...

  5. IDE set arguments

    2019独角兽企业重金招聘Python工程师标准>>> code::blocks -> Project -->set program's arguments qtcrea ...

  6. 解决Undefined function or method 'vgg_kmiter' for input arguments of type 'double'.

    Undefined function or method 'vgg_kmiter' for input arguments of type 'double'. Error in ==> vgg_ ...

  7. 浅析js中的arguments

    arguments就是传递进函数的参数列表,它是一个类数组对象-Array-Like Object. 类数组对象,简单来说就是拥有length属性,如我们常用的NodeList,arguments,但 ...

  8. Error in select(., cyl, mpg) : unused arguments (cyl, mpg)

    Error in select(., cyl, mpg) : unused arguments (cyl, mpg) 目录 Error in select(., cyl, mpg) : unused ...

  9. oracle ora 13011,ORA-00600: internal error code, arguments: [13011]

    近期,一客户历史数据库屡次遇到ORA-00600: internal error code, arguments: [13011].附带的,还有ORA-01499 SQL> analyze ta ...

  10. python调用dll报错:ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong call

    python调用dll报错:ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong call ...

最新文章

  1. linux 进程等待 wait 、 waitpid
  2. CSS:超出部分省略号
  3. 2019年六月刷题列表
  4. 常用对照表之TCP及UDP常见端口参照
  5. 集成 AquaLogic BPM Suite 6.0 和 AquaLogic Service Bus
  6. uva 10140——Prime Distance
  7. 算法----(3)选择排序
  8. 直观理解Hilbert空间是什么?
  9. InstallShield教程-打包.NET程序
  10. 常用的开源3D游戏引擎(转)
  11. 查看树莓派引脚以及串口连接
  12. 机房建设整体设计方案
  13. 组件上传之AspUpload使用方法
  14. 如何在python同一行内输入若干个数?
  15. 《大学生Python学习》社区正式运行,加入我们,每日学习,引燃青春~
  16. 基于java设计小游戏目的_java小游戏设计
  17. Andersen Global与斯德哥尔摩律所合作,扩大瑞典业务版图
  18. 计算机配置好坏怎么看,怎么看电脑配置,电脑配置好坏信息一目了然-腾讯电脑管家...
  19. “金三银四”春招指南!java语言程序设计第二版答案朱庆生
  20. 2022年,继续奋斗。

热门文章

  1. JDK Long源码
  2. 读《程序员必读的职业规划书》
  3. Tomcat-简易使用教程
  4. Java程序员从笨鸟到菜鸟之(九)——数据库有关知识补充(事务、视图、索引、存储过程)
  5. Java 包(package)
  6. 斯坦福大学深度学习与自然语言处理第四讲:词窗口分类和神经网络
  7. Python IDLE或Python Shell不支持中文编码的解决方案
  8. 深度学习(八)RBM受限波尔兹曼机学习-未完待续
  9. 大数据小白系列——HDFS(3)
  10. 介绍几个移动web app开发框架