function Car(sColor, iDoors, iMpg) {
this.color = sColor;
this.doors = iDoors;
this.mpg = iMpg;
this.showColor = function () {
alert(this.color)
};
//这样存在一个问题,就是每次创建新对象时,都会产生一个新的方法showColor的副本,因此可以这样写:
//this.showColor=showColor;
}
function showColor() {
alert(this.color);
}
var oCar1 = new Car("red", 4, 23);
var oCar2 = new Car("blue", 3, 25);