当前位置:网站首页>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 !');
}
边栏推荐
- Vulnhub's breach1.0 range exercise
- Simple understanding of pseudo elements before and after
- text-overflow失效
- Metasploitabile2 target learning
- Using idea to add, delete, modify and query database
- 通过两种方式手写一个消息队列
- ERROR 1215 (HY000): Cannot add foreign key constraint
- FPGA设计——乒乓操作实现与modelsim仿真
- Why is it that the live video of the devices connected to easygbs suddenly cannot be played? Insufficient database read / write
- FPGA interview notes (III) -- implementation of handshake signal synchronization in cross clock domain, arbitrary frequency division, binary conversion, RAM memory, original code inversion and complem
猜你喜欢

FPGA面試題目筆記(四)—— 序列檢測器、跨時鐘域中的格雷碼、乒乓操作、降低靜動態損耗、定點化無損誤差、恢複時間和移除時間

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

Multimedia框架解析之MediaExtractor源码分析(一)

About the principle and code implementation of Siou (review IOU, giou, Diou, CIO)

This point of arrow function

Sqli-labs less-01

PHP laravel8 send email

Convert multiple pictures into one NPY file storage

Metasploitabile2 target learning

Learn a trick to use MySQL functions to realize data desensitization
随机推荐
Stock K-line drawing
Wechat applet (authorized login) (not recommended, click the home page to view the updated authorized login)
Error reporting injection of SQL injection
MongoDB安装
FPGA面試題目筆記(四)—— 序列檢測器、跨時鐘域中的格雷碼、乒乓操作、降低靜動態損耗、定點化無損誤差、恢複時間和移除時間
Convert text label of dataset to digital label
Detailed installation instructions for MySQL
Simple understanding of pseudo elements before and after
UEFI查找PCI设备
Eureka cluster setup
go的fmt包使用和字符串的格式化
FMT package usage of go and string formatting
Jenkins user rights management
Handwriting promise [02] - asynchronous logic implementation
FPGA面试题目笔记(三)——跨时钟域中握手信号同步的实现、任意分频、进制转换、RAM存储器等、原码反码和补码
563. 二叉树的坡度
Teach everyone how to implement an electronic signature
Use of constructors
Alias the path with the help of craco
Fix the problem that the right mouse button does not have a vscode shortcut