arguments

用于存储和访问函数参数的参数对象

公共属性:

1. callee:Function 当前正在执行函数的引用。

2. length:Number 参数数目。

 

递归函数尽量采用arguments,防止函数名有变化,导致错误。

function factorial(num){
    if(num == 1)
        return 1;
    else
        return num * arguments.callee(num - 1);
}

document.write(factorial(10));

arguments 参数存储为数组元素

第一个为 arguments[0], 第二个 arguments[1], ...

function print(str){
    document.write(arguments[0]); // Hello the world
}

print("Hello the world");

or

(function print(str){
    document.write(arguments[0]); // Hello the world
})("Hello the world");

 

posted @ 2014-12-05 13:40  lcw5945  阅读(151)  评论(0编辑  收藏  举报