匿名函数递归
1 function factorial(num) {
2 if (num <= 1) {
3 return 1;
4 } else {
5 return num * arguments.callee(num - 1);
6 }
7 }
2 if (num <= 1) {
3 return 1;
4 } else {
5 return num * arguments.callee(num - 1);
6 }
7 }
命名函数递归
1 function factorial(num) {
2 if (num <= 1) {
3 return 1;
4 } else {
5 return num * factorial(num - 1);
6 }
7 }
2 if (num <= 1) {
3 return 1;
4 } else {
5 return num * factorial(num - 1);
6 }
7 }
调用函数
1 var trueFactorial = factorial;
2 factorial = function () {
3 return 0;
4 };
5 console.log(trueFactorial(5));
6 console.log(factorial(5));
3 return 0;
4 };
5 console.log(trueFactorial(5));
6 console.log(factorial(5));