Javascript基本教程的详细解释
参数是Javascript中函数中的一个特殊参数,如以下参数,使用参数访问函数参数以确定函数是否执行。复制代码代码如下所示:
函数sayHello(){
如果(参数{ 0 }再见)
返回;
其他的
警报(++参数{ 0 });
}
参数的长度属性可以用来返回参数的个数。
复制代码代码如下所示:
功能cnumbarg(){
返回arguments.length;
}
document.write(cnumbarg(252255,你好)+); / /返回3
(cnumbarg document.write()+); / / 0
document.write(cnumbarg(1111)+); / / 1
使用参数对象模拟函数的重载
复制代码代码如下所示:
功能fnadd(){
如果(arguments.length = 0)
返回;
如果(arguments.length = 1)
返回参数{ 0 } + 5;
其他(arguments.length > 1)
var ISUM = 0
对于(var i = 0;i < arguments.length;i++)
ISUM =参数{我};
返回ISUM;
}
document.write(fnadd(5)+ );
document.write(fnadd(10)+ );
document.write(fnadd(10,20)+ );
document.write(fnadd(10、20、30、40)+ );
是否对合作伙伴有了新的认识,事实上,他可以做更多的事情,童鞋自己思考越来越多的尝试。