当前位置:网站首页>arguments......
arguments......
2022-06-11 06:28:00 【Saucey_ six】
Let's start with a piece of code :
function diTui(n) {
if(n===1){
return n
}
return diTui(n-1)*n
}
var test=diTui;
test=undefined;
test(5);
ask , Can this code be executed effectively ?
answer : Can not be , stay diTui To be an assignment undefined When , It has already failed
It's actually incorrect Of , The point of his investigation is not here
Let's look at another piece of code :
function diGui(n) {
if(n===1){
return n
}
return arguments.callee(n-1)*n
}
var test=diGui;
test(5);
This code will work properly
It's obvious , We used in recursion args A property of ,args.callee Instead of pointing to the anonymous function being executed .
arguments
1.arguments Is not an array , But with arrays length And index element attributes
2.arguments Convert to an arrayvar args=Array.prototype.slice.apply(str,arguments)
3.arguments Defined callee and caller attribute .
4. all ( Except arrow function ) A local variable of a function , have access to args The object references a function's arguments in a function .
5.arguments It's an object .
arguments.callee( Points to the currently executing function )
- Used in anonymous recursive functions , Decoupling between function names and functions can be realized , After modifying the function name , Function internals can remain unchanged .
function jieChen(){
return function(n){
if(n<=1) return 1
return n*arguments.callee(n-1)
}
}
- Alternative , because args.callee It costs a lot to use
function jieChen(n){
if(n<=1) return 1;
let result=1;
return (function fn(){
result*=n
n--;
if(n!=0){
fn()
}
return result
})()
}
There is an interview question :
Accept parameters , Loop out array 【1,2,3,4,5】, Out of commission for loop .
function show(n){
let result=[]
return (function () {
result.unshift(n)
n--
if(n!=0){
arguments.callee();
}
return result
})()
}
arguments.caller( Points to the function that calls the current function )
function whoCalled() {
if (arguments.caller == null)
console.log(' This function is called in the global scope .');
else
console.log(arguments.caller + ' Called me !');
}
边栏推荐
- Learn a trick to use MySQL functions to realize data desensitization
- FPGA面试题目笔记(三)——跨时钟域中握手信号同步的实现、任意分频、进制转换、RAM存储器等、原码反码和补码
- 不同VLAN间的通信
- FMT package usage of go and string formatting
- Chapter 1 of machine learning [series] linear regression model
- 动态import
- LeetCodeT526
- []==![]
- Teach everyone how to implement an electronic signature
- 关于parseInt()
猜你喜欢

572. 另一个树的子树
![Chapter 2 of machine learning [series] logistic regression model](/img/8f/b4c302c0309f5c91c7a40e682f9269.jpg)
Chapter 2 of machine learning [series] logistic regression model

Jenkins user rights management

Communication between different VLANs

538.把二叉搜索树转换成累加树

verilog实现双目摄像头图像数据采集并modelsim仿真,最终matlab进行图像显示

EasyGBS接入的设备视频直播突然全部无法播放是为什么?数据库读写不够

通过两种方式手写一个消息队列
![[reading this article is enough!!! Easy to understand] confidence level understanding (95% confidence level and confidence interval)](/img/d6/e61ba5bad2b2847378c4547ce0780d.jpg)
[reading this article is enough!!! Easy to understand] confidence level understanding (95% confidence level and confidence interval)

Teach everyone how to implement an electronic signature
随机推荐
Differences between FindIndex and indexof
Human gene editing technology and ethical issues behind it [personal view, for reference only]
021-MongoDB数据库从入门到放弃
Learn a trick to use MySQL functions to realize data desensitization
fatal: refusing to merge unrelated histories
学好C语言从关键字开始
break,continue有什么区别和用法?
This point of arrow function
Chapter 1 of machine learning [series] linear regression model
Error reporting injection of SQL injection
jenkins-不同风格的项目构建
FPGA interview notes (IV) -- sequence detector, gray code in cross clock domain, ping-pong operation, static and dynamic loss reduction, fixed-point lossless error, recovery time and removal time
Learn C language well from keywords
About the principle and code implementation of Siou (review IOU, giou, Diou, CIO)
CCS method of installing compiler
On the social moral and ethical issues behind short videos (personal point of view, for reference only)
FIFO最小深度计算的题目合集
PHP laravel8 send email
Docker installation of MySQL and redis
QT socket设置连接超时时间