In programming languages, the function Func(Type a,...) calls the function itself directly or indirectly, and the function is called a recursive function. Recursive functions cannot be defined as inline functions.
Recursive functions:
function factorial(num){ if(num<=1){ return 1; } else{ return num*factorical(num-1); }}factorial(2)//2This recursive function uses a function to call the function itself, but is this really good? Let's take a look at it here.
var another=factorical;factorical=null;console.log(another(2))//There will report an error saying factorial not a function
This is the disadvantage of function calling functions. How to solve it? See below
function factorial(num){ if(num<=1){ return 1; } else{ return num*arguments.callee(num-1); }}var another=factorical;factorical=null;console.log(another(2))//2The above use arguments.callee instead of function name to ensure that no matter how the function is called, there will be no errors.
The above is the recursive function in JS introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!