本文阐述了js简单工厂模式的用法,供大家参考,具体实现方法如下:





简单工厂模式



简单工厂模式
Var(bicycleshop =功能){ };
bicycleshop.prototype = {
SellBicycle:函数(模型){
var自行车=空;
开关(模型){
case'the Speedster ':
自行车=新快车();
打破;
case'the lowride:
自行车=新lowride();
打破;
case'the舒适巡航:
自行车=新comfortcruise();
打破;
};
interface.ensureimplements(自行车、自行车);
Bicycle.assemble();
bicycle.wash();
返回自行车;
}
};
Var(acmebicycleshop =功能){ };
(acmebicycleshop程度,bicycleshop);
acmebicycleshop.prototype.createbicycle =函数(模型){
var自行车=空;
开关(模型){
case'the Speedster ':
自行车=新acmespeedster();
打破;
case'the车:
自行车=新AcmeLowrider();
打破;
case'the平面:
自行车=新AcmeFlatlander();
打破;
case'the舒适巡洋舰:
违约:
自行车=新AcmeComfortCruiser();
};
interface.ensureimplements(自行车、自行车);
返回自行车;
};
具有不同参数的FN应用程序的工厂模型,创建不同的对象







希望本文能对大家的javascript程序设计有所帮助。