javascript中定义类和对象最好的方法

function Car(sColor,iDoors,iMpg){
this.color=sColor;
this.doors=iDoors;
this.mpg=iMpg;
this.drivers=new Array("Mike", "Sue");
}
Car.prototype.showColor =function(){
alert(this.color);
}

var oCar1=new Car("red",4,23);


或者是
function Car(sColor,iDoors,iMpg){
this.color=sColor;
this.doors=iDoors;
this.mpg=iMpg;
this.drivers=new Array("Mike", "Sue");
if(typeof Car._initialized=="undefined")
{
    Car.prototype.showColor=function(){
    alert(this.color);
    };
    Car._initialized=true;
}


}

posted on 2007-10-29 17:59 刘铮 阅读(336) 评论(0)  编辑  收藏 所属分类: JavaScript


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论