If you want to know the purpose of your code and the function of arguments.callee, you can first follow me and modify your code twice, see the effect, and summarize it yourself, and then look at the rough explanation
Method 1
Add a line of code: alert(1); 并在调用的fn()后面再添加一个括号[ 改为fn()() ], the final result is:
function f()
{
alert(1);
return arguments.callee();
}
f()();
Method 2
Add a line of code: alert(1);,并将arguments.callee;改为arguments.callee();, the final result is as follows:
function f()
{
alert(1);
return arguments.callee();
}
f();
Explanation
arguments is a built-in object in JS, existing in any function [function], and callee is a method in the arguments object that points to the function body that calls it. Here it is equivalent to f,调用callee等同于你又调用了一次f. In fact, callee is in most cases Used inside anonymous functions, such as:
arguments.callee is this function. It seems that ES6 is no longer recommended.
The code of the question is equivalent to
Return the function body itself
If you want to know the purpose of your code and the function of arguments.callee, you can first follow me and modify your code twice, see the effect, and summarize it yourself, and then look at the rough explanation
Method 1
Add a line of code:
alert(1);
并在调用的fn()
后面再添加一个括号[ 改为fn()()
], the final result is:Method 2
Add a line of code:
alert(1);
,并将arguments.callee;
改为arguments.callee();
, the final result is as follows:About
return
The return here is to return the entire function itself·f
You can know the
arguments.callee
就等同于f
here through the above explanation, such as:Error reporting in strict mode. Using this is not recommended.