ITeye博客

JavaScript函数中arguments对象

yeminping · 2009-01-10 13:47 · web · Markdown

JavaScript 函数中 arguments 为特殊对象,无需明确指出参数名,就能访问它们。用 arguments[0], arguments[1] 依次类推出参数。如

 

function sayHello() {

                if (arguments[0] == "bye")

                     return;

 

                alert(arguments[0]);

            }

 

1.       调用 sayHello(‘bye’) , 直接返回,无任何信息

2.       调用 sayHello(‘HelloWorld’), 提示 ”HelloWorld”

 

 

  Arguments 还提供了一个属性 arguments.length, 作用于参数个数 :

 

  funcion args() {

       alert(arguments.length);

}

 

args(‘a’, 1)     // 提示 2

args()    // 提示 0

args(23)    // 提示 1

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。