当前位置:网站首页>Usage of arguments.callee
Usage of arguments.callee
2022-07-26 02:43:00 【Brave * Niuniu】
argument Is the internal object of the function , Contains all the parameters of the incoming function ,arguments.callee Represents the function name , Used for recursive calls , Prevent tight coupling between function execution and function name , It also works well for anonymous functions that don't have a function name . Examples are as follows :
function factorial(num){
if(num<=1){
return 1;
}else{
return num*arguments.callee(num-1); //arguments.callee representative factorial
}
}
var trueFactorial = factorial;
factorial = function(){
return 0;
}
alert(trueFactorial(5)); // The result is 120, because js No overload for function in , So if you use the function name when calling recursively , Then execute the last function with this function name , Return 0
alert(factorial(5));// The result is 0
Recursion of anonymous functions :
var num = (function(num){
if(num<=1){
return 1;
}else{
return num*arguments.callee(num-1);
}
})(5);
alert(num); // The result is 120
Traffic light asynchronous output
function showRed(fn1, fn2){
var f = arguments.callee; // The function itself
//arguments.callee The context execution environment in which this function is executed , Point to the object that called him
setTimeout(function(){
console.log(" A red light ");
fn1(fn2, f);
}, 2000);
}
function showYellow(fn1, fn2){
var f = arguments.callee;
setTimeout(function(){
console.log(" Yellow light ");
fn1(fn2, f);
}, 1000);
}
function showGreen(fn1, fn2){
var f = arguments.callee;
setTimeout(function(){
console.log(" A green light ");
fn1(fn2, f);
}, 3000);
}
showRed(showYellow, showGreen);
边栏推荐
- (Dynamic Programming Series) sword finger offer 48. the longest substring without repeated characters
- Manifold learning
- [pure theory] Yolo v4: optimal speed and accuracy of object detection
- Adruino basic experimental learning (I)
- Get hours, minutes and seconds
- 1. Software testing ----- the basic concept of software testing
- 信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
- [early knowledge of activities] list of recent activities of livevideostack
- Image recognition (VII) | what is the pooling layer? What's the effect?
- Article setting top
猜你喜欢

Adruino basic experimental learning (I)

Games101 review: rasterization

JS get the time composition array of two time periods

TCP三次握手四次挥手

(PC+WAP)织梦模板蔬菜水果类网站

ES6 advanced - inherit parent class attributes with constructors

Turn on the LED

如何有效的去防止别人穿该网站首页快照

Simply use MySQL index
![[steering wheel] how to transfer the start command and idea: VM parameters, command line parameters, system parameters, environment variable parameters, main method parameters](/img/97/159d7df5e2d11b129c400d61e3fde6.png)
[steering wheel] how to transfer the start command and idea: VM parameters, command line parameters, system parameters, environment variable parameters, main method parameters
随机推荐
pbootcms上传缩略图尺寸自动缩小变模糊
Games101 review: shading, rendering pipelines
【方向盘】工具提效:Sublime Text 4的常用快捷键合集
From a data incremental processing problem, we can see the consciousness gap of technicians
Literature speed reading | in the face of danger, anxious people run faster?
DFS Niuke maze problem
【方向盘】启动命令和IDEA如何传递:VM参数、命令行参数、系统参数、环境变量参数、main方法参数
MySQL build websites data table
U++ common type conversion and common forms and proxies of lambda
ES6高级-利用构造函数继承父类属性
ES6高级-利用原型对象继承方法
I hope you can help me with MySQL
简单使用 MySQL 索引
Prometheus + redis exporter + grafana monitor redis service
[pure theory] Yolo v4: optimal speed and accuracy of object detection
信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
Prove that perfect numbers are even
The sixth day of the third question of daily Luogu
ERROR: could not extract tar starting at offset 000000000000020980+9231072+2
Digital warehouse: on the construction practice of digital warehouse in banking industry