87,993
社区成员
发帖
与我相关
我的任务
分享//js模拟重载
function add2(){
document.write("<br/>");
//判断传入的参数的个数
if(arguments.lenght == 2){
return arguments[0]+arguments[1];
}else if (arguments.lenght == 3){
return arguments[0]+arguments[1]+arguments[2];
}else if (arguments.length == 4){
return arguments[0]+arguments[1]+arguments[2]+arguments[3];
}else
return 0;
}
document.write("2个参数: "+add2(1,2));
document.write("3个参数: "+add2(1,2,3));
document.write("4个参数: "+add2(1,2,3,4));
document.write("5个参数: "+add2(1,2,3,4,5));