关于arguments
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相关推荐
- JavaScript arguments对象
1.在JavaScript中,arguments对象是比较特别的一个对象,实际上是当前函数的一个内置属性.arguments非常类似Array,但实际上又不是一个Array实例.可以通过如下代码得以证 ...
- 【Qt】Qt再学习(十六):QObject::connect: Cannot queue arguments of type ‘QString‘
1.问题描述 跨线程使用信号和槽时,如果是非const的引用传参,就会报如下的错误: QObject::connect: Cannot queue arguments of type 'QString ...
- java unlimited_具有无限参数的Java方法(Java method with unlimited arguments)
具有无限参数的Java方法(Java method with unlimited arguments) Spring框架使用方法,您可以根据需要传递尽可能多的参数. 我想写一个函数,也可以采取无限量的 ...
- javascript函数嵌套时arguments的问题
疑问: var funtest = function () {var fun = function (val, val2) {alert(arguments.length); //此处答案? 有些人回 ...
- IDE set arguments
2019独角兽企业重金招聘Python工程师标准>>> code::blocks -> Project -->set program's arguments qtcrea ...
- 解决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_ ...
- 浅析js中的arguments
arguments就是传递进函数的参数列表,它是一个类数组对象-Array-Like Object. 类数组对象,简单来说就是拥有length属性,如我们常用的NodeList,arguments,但 ...
- Error in select(., cyl, mpg) : unused arguments (cyl, mpg)
Error in select(., cyl, mpg) : unused arguments (cyl, mpg) 目录 Error in select(., cyl, mpg) : unused ...
- oracle ora 13011,ORA-00600: internal error code, arguments: [13011]
近期,一客户历史数据库屡次遇到ORA-00600: internal error code, arguments: [13011].附带的,还有ORA-01499 SQL> analyze ta ...
- 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 ...
最新文章
- linux 进程等待 wait 、 waitpid
- CSS:超出部分省略号
- 2019年六月刷题列表
- 常用对照表之TCP及UDP常见端口参照
- 集成 AquaLogic BPM Suite 6.0 和 AquaLogic Service Bus
- uva 10140——Prime Distance
- 算法----(3)选择排序
- 直观理解Hilbert空间是什么?
- InstallShield教程-打包.NET程序
- 常用的开源3D游戏引擎(转)
- 查看树莓派引脚以及串口连接
- 机房建设整体设计方案
- 组件上传之AspUpload使用方法
- 如何在python同一行内输入若干个数?
- 《大学生Python学习》社区正式运行,加入我们,每日学习,引燃青春~
- 基于java设计小游戏目的_java小游戏设计
- Andersen Global与斯德哥尔摩律所合作,扩大瑞典业务版图
- 计算机配置好坏怎么看,怎么看电脑配置,电脑配置好坏信息一目了然-腾讯电脑管家...
- “金三银四”春招指南!java语言程序设计第二版答案朱庆生
- 2022年,继续奋斗。