2008-12-20
javascrpt中的匿名函数递归
javascrpt中的匿名函数递归依靠arguments.callee
1. function factorial(n) {
2.
3. if (n <= 0) {
4.
5. return 1;
6. }
7.
8. else {
9.
10. return n * arguments.callee(n - 1);
11. }
12.
13. }
14.
15. alert(factorial(4));
2.
3. if (n <= 0) {
4.
5. return 1;
6. }
7.
8. else {
9.
10. return n * arguments.callee(n - 1);
11. }
12.
13. }
14.
15. alert(factorial(4));