Discussing how to define JavaScript (1) factory-based JavaScript face object

Source: Internet
Author: User

CopyCode The Code is as follows: // The automobile factory in 1960s
VaR ocar = new object;
Ocar. color = "black ";
Ocar. Doors = 2;
Ocar. pinpai = "Liberation ";
Ocar. showpinpai = function ()
{
Alert (this. pinpai); // a production line is required to generate an automobile and create a new production line for the next automobile.
}
// Automobile factory in 1970s
Function createcar ()
{
VaR otempcar = new object;
Otempcar. color = "black ";
Otempcar. Doors = 4;
Otempcar. pinpai = "santana ";
Otempcar. showpinpai = function ()
{
Alert (this. pinpai); // convenient production. One production line can produce multiple vehicles.
}
Return otempcar;
}
// Automobile production in 1980s

Function createcar (scolor, idoors, spinpai)
{
VaR otempcar = new object;
Otempcar. Color = scolor;
Otempcar. Doors = idoors;
Otempcar. pinpai = spinpai;
Otempcar. showpinpai = function ()
{
Alert (this. pinpai); // convenient production and one-time molding
}
Return otempcar;
}
// Automobile production in 1990s
Function showpinpai ()
{
Alert (this. Color );
}

function createcar (scolor, idoors, spinpai)
{< br> var otempcar = new object;
otempcar. color = scolor;
otempcar. doors = idoors;
otempcar. pinpai = spinpai;
otempcar. showpinpai = function ()
return otempcar;
}< br> var obmw = createcar ("black", 4, "BMW");
obmw. showcolor (); // One-time molding + assembly and production

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.