码迷,mamicode.com
首页 > 其他好文 > 详细

arguments

时间:2014-12-05 14:15:23      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

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

公共属性:

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");

 

arguments

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/lcw5945/p/4146496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!