function car(sColor){
this.color=sColor;
if(typeof car._initialized =="undefined"){
car.prototype.show=function(){
alert(this.color);
}
}
}car.prototype.show=function (){
alert("hello world");
}var s=new car();
s.show();
为什么不输出hello world,而输出undefined
this.color=sColor;
if(typeof car._initialized =="undefined"){
car.prototype.show=function(){
alert(this.color);
}
}
}car.prototype.show=function (){
alert("hello world");
}var s=new car();
s.show();
为什么不输出hello world,而输出undefined
而在car()里因为typeof car._initialized =="undefined"成立,所以每当new car()的时候,car.prototype.show都会被修改成为
function(){
alert(this.color);
}
而你的new car()中没有参数,所以得到undefined
alert("hello world");
}
不可以把前面的方法覆盖掉么,