Javascript arguments.callee what is it for

后端 未结 5 1638
无人共我
无人共我 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:09

    arguments.callee is a round about way of knowing the current executing function by asking 'Who is calling this specific argument?' . . . .

     function factorial(a){
        if(a>0)
          return a*arguments.callee(a-1);
     }
    

    Here if you call factorial(5), it will check for condition greater than 0, and if it is true, will execute the same logic for the next lesser number . . . In some cases you don't know the name of the function to be called . . . .so you can use this property

    here is a good reference

    arguments.callee from MDN

    UPDATE: arguments.callee() is deprecated in ES5

提交回复
热议问题