javascript(一)工場方式js面像対象の定義方法を討論する.

1521 ワード

 
  
//60
var ocar=new Object;
ocar.color="black";
ocar.doors=2;
ocar.pinpai=" ";
ocar.showPinpai=function()
{
  alert(this.pinpai);// , ,
}
//70
function createcar()
{
   var oTempCar=new Object;
  oTempCar.color="black";
   oTempCar.doors=4;
   oTempCar.pinpai=" ";
   oTempCar.showPinpai=function()
  {
    alert(this.pinpai);// , ,
  }
    return oTempCar;
}
//80

function createcar(sColor,iDoors,sPinpai)
{
   var oTempCar=new Object;
  oTempCar.color=sColor;
   oTempCar.doors=iDoors;
   oTempCar.pinpai=sPinpai;
   oTempCar.showPinpai=function()
  {
    alert(this.pinpai);// ,
  }
  return oTempCar;
}
//90
function showPinpai()
{
   alert(this.color);
}

function createcar(sColor,iDoors,sPinpai)
{
   var oTempCar=new Object;
  oTempCar.color=sColor;
   oTempCar.doors=iDoors;
   oTempCar.pinpai=sPinpai;
   oTempCar.showPinpai=function()
  return oTempCar;
}
var oBmw=createcar("black",4,"BMW");
oBmw.showColor();// +