//模拟函数重载
function person() {
var xx=arguments;
if(typeof xx[0]=='object'&&xx[0]){
if(xx[0].name){
this.name=xx[0].name;
}
if(xx[0].age){
this.age=xx[0].age;
}
}else{
if(xx[0]){
this.name=xx[0];
}
if(xx[1]){
this.age=xx[1];
}
}
}
person.prototype.toString=function () {
return 'name='+this.name+',age='+this.age;
}
var std1=new person('lihua',27);
console.log(std1.toString());
var std2=new person({name:'liwei',age:24});
console.log(std2.toString())
用javascript来模拟实现函数重载
最新推荐文章于 2023-09-29 00:09:31 发布
1003

被折叠的 条评论
为什么被折叠?



