Home >Web Front-end >JS Tutorial >Discuss javascript (1) factory method definition method of js object-oriented object_js object-oriented

Discuss javascript (1) factory method definition method of js object-oriented object_js object-oriented

WBOY
WBOYOriginal
2016-05-16 18:39:161048browse
Copy code The code is as follows:

//Car factory in the 1960s
var ocar=new Object ;
ocar.color="black";
ocar.doors=2;
ocar.pinpai="Liberation";
ocar.showPinpai=function()
{
alert (this.pinpai);//A production line is needed to produce a car, and a new production line needs to be built to produce the next car
}
//Car factory in the 1970s
function createcar()
{
var oTempCar=new Object;
oTempCar.color="black";
oTempCar.doors=4;
oTempCar.pinpai="Santana"; )
 {
 alert(this.pinpai); // Convenient production, one production line can produce multiple cars
 }
  return oTempCar;
}
//Produced in the 1980s Car

function createcar(sColor,iDoors,sPinpai)
{
var oTempCar=new Object;
oTempCar.color=sColor; oTempCar.pinpai=sPinpai;
oTempCar.showPinpai=function()
{
alert(this.pinpai);//Convenient production, one-time molding
}
return oTempCar;
}
//Cars produced in the 90s
function showPinpai()
{
  alert(this.color);
}

function createcar(sColor,iDoors,sPinpai )
{
var oTempCar=new Object;
oTempCar.color=sColor;
oTempCar.doors=iDoors;
oTempCar.pinpai=sPinpai; )
 return oTempCar;
}
var oBmw=createcar("black",4,"BMW");
oBmw.showColor();//One-time molding and assembly production

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn