function Person(){
this.test=function (){
if(arguments.length==1){
this.speak1(arguments[0]);
}else if(arguments.length==2){
this.speak2(arguments[0],arguments[1]);
}else if(arguments.length==3){
this.speak3(arguments[0],arguments[1],arguments[2]);
}
}
this.speak1=function(a){
window.alert("speak1()被调用"+a);
}
this.speak2=function(a,b){
window.alert("speak2()被调用"+"-"+a+"-"+b);
}
this.speak3=function(a,b,c){
window.alert("speak3()被调用"+"-"+a+"-"+b+"-"+c);
}
}
var p1=new Person();
//注:js中是不支持重载.
p1.test("a");
p1.test("a","b");
p1.test("a","b","c");
</script>
JS----Overload 重载
最新推荐文章于 2020-08-19 23:20:05 发布