function f (){
return arguments.callee;
}
f();
What is the function of return here?
给我你的怀抱2017-05-16 13:24:39
arguments.callee is this function. It seems that ES6 is no longer recommended.
The code of the question is equivalent to
function f (){
return f;
}
phpcn_u15822017-05-16 13:24:39
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
Add a line of code: alert(1);
并在调用的fn()
后面再添加一个括号[ 改为fn()()
], the final result is:
function f()
{
alert(1);
return arguments.callee();
}
f()();
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:
(function(){
alert(1);
return arguments.callee();
})()
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:
function f()
{
alert(1);
return arguments.callee;
}
f();
↑↓等价于
function f()
{
alert(1);
return function f(){
alert(1);
};
}
f();