javascript - arguments.callee
某草草
某草草 2017-05-16 13:22:39
0
4
435
function f (){
    return arguments.callee;
}


f();

What is the function of return here?

某草草
某草草

reply all(4)
给我你的怀抱

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;
}
左手右手慢动作

Return the function body itself

phpcn_u1582

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:

    (function(){
        alert(1);
        return arguments.callee();
    })()

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:

function f()
{
    alert(1);
    return arguments.callee;
}
f();

↑↓等价于

function f()
{
    alert(1);
    return function f(){
            alert(1);
            };
}
f();
某草草

Error reporting in strict mode. Using this is not recommended.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template