日期:2014-05-16 浏览次数:20472 次
function createCar(sColor,iDoors,iMpg){ var oTempCar = new Object(); oTmepCar.color = sColor; oTmepCar.doors= iDoors; oTmepCar.mpg= iMpg; oTmepCar.showColor = funtion (){ alert (this.color); }; return oTempCar; } var oCar1 = createCar('red',4,23); var oCar1 = createCar('blue',3,25); oCar1.showColor(); oCar2.showColor();
function Car(sColor,iDoors,iMpg){ this.color = sColor; this.doors= iDoors; this.mpg= iMpg; this.showColor = function (){ alert(this.color); } } var oCar1 = new Car('red',3,25); var oCar2 = new Car('blue',5,25);
function Car(){} Car.prototype.color = 'red'; Car.prototype.doors = '4'; Car.prototype.mpg = '25'; Car.prototype.drivers = new Array('a','b'); Car.prototype.showColor = function (){ alert(this.color); }; var oCar1 = new Car(); var oCar2 = new Car();
function Car(sColor,iDoors,iMpg){ this.color = sColor; this.doors = iDoors; this.mpg = iMpg; this.drivers = new Array('a','b'); } Car.prototype.showColor = function (){ alert(this.color); } var oCar1 = new Car('red',3,25); var oCar2 = new Car('blue',5,25);
function Car(sColor,iDoors,iMpg){ this.color = sColor; this.doors = iDoors; this.mpg = iMpg; this.drivers = new Array('a','b'); if(typeof Car._initialized == "undefined"){ Car.prototype.showColor = function (){ alert(this.color); } Car._initialized = true; } }