Javascript arguments.callee what is it for

后端 未结 5 1645
无人共我
无人共我 2020-12-13 19:24

I haven\'t found any complete cross-browser doc of this variable.

What is arguments.callee for? how does it work?

Which arguments does it have?

5条回答
  •  甜味超标
    2020-12-13 20:08

    It specifies the currently executing function, so arguments.callee is the current function. It may be helpfull if you need to go recursive in anonimous function. Here example from mozilla:

    function create() {
       return function(n) {
          if (n <= 1)
             return 1;
          return n * arguments.callee(n - 1);
       };
    }
    
    var result = create()(5); // returns 120 (5 * 4 * 3 * 2 * 1)
    

提交回复
热议问题