search

Home  >  Q&A  >  body text

javascript - arguments.callee

function f (){
    return arguments.callee;
}


f();

What is the function of return here?

某草草某草草2756 days ago428

reply all(4)I'll reply

  • 给我你的怀抱

    给我你的怀抱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;
    }

    reply
    0
  • ringa_lee

    ringa_lee2017-05-16 13:24:39

    Return the function body itself

    reply
    0
  • phpcn_u1582

    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

    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();

    reply
    0
  • 某草草

    某草草2017-05-16 13:24:39

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

    reply
    0
  • Cancelreply