JavaScript Arguments 实现可变参数的函数,以及函数的递归调用

 1 //可变参数的函数  注:也可以使用对象作为参数来实现
 2 function Max() {
 3     var temp = arguments[0] || 0;
 4     for (var i = 1; i < arguments.length ; i++) {
 5         if (arguments[0] < arguments[i]) {
 6             temp = arguments[i];
 7             arguments[i] = arguments[0];
 8             arguments[0] = temp;
 9         }
10     }
11     return arguments[0] || 0;
12 }
13 console.log(Max(23, 65, 25, 8, 9, 345, 5, 88));

输出:
345

1 //使用Arguments的callee属性对本函数进行调用:实现递归, callee属性代表此函数本身
2 function jiecheng(x) {
3     if (x <= 1)
4         return 1;
5     return x * arguments.callee(x - 1);
6 
7 }
8 console.log(jiecheng(3));

输出:

6

原文地址:https://www.cnblogs.com/tlxxm/p/4361920.html