<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
function Car(options){
this.doors = options.doors || 4;
this.state = options.state || "brand new";
this.color = options.color || "silver";
};
function Truck(options){
this.state = options.state || "used";
this.wheelSize = options.wheelSize || "large";
this.color = options.color || "blue";
};
function VehicleFactory(){};
VehicleFactory.prototype.vehicleClass = Car;
VehicleFactory.prototype.createVehicle = function( options ){
if(options.vehicleType == "car"){
this.vehicleClass = Car;
}else{
this.vehicleClass = Truck;
};
return new this.createVehicle(options);
};
var carFactory = new VehicleFactory({
vehicleType : 'truck',
state : 'like new',
color : 'red',
wheelSize : 'small'
});
console.log( carFactory instanceof VehicleFactory);
console.log( carFactory ); function TruckFactory(){};
TruckFactory.prototype = new VehicleFactory();
TruckFactory.prototype.vehicleClass = 'truck'; var truckFactory = new TruckFactory();
console.log( truckFactory instanceof TruckFactory); //抽象 工厂模式---->_->
var AbstractVehicleFactory = (function(){
//定义车辆的类型,用来存储数据
var types = {};
return {
registerVehicle : function(type,vehicle){
types[type] = vehicle;
},
getVehicle : function(type,customizatoins){
var vehicle = types[type];
return (vehicle) ? new topics[type](customizations) : null;
}
}
})();
</script>
</body>
</html>

最新文章

  1. Java Web技术之Cookie
  2. struts深入理解之登录示例的源码跟踪
  3. Mysql命令大全&amp;&amp;指定端口登录
  4. 有哪些可以将网页另存图片的chrome插件?功能类似网页截图
  5. UVa10723 - Cyborg Genes
  6. Entity Framework分页扩展
  7. SpringBoot之常用注解
  8. spring boot 开始部署报Whitelabel Error Page错解决方法
  9. ArcGIS案例教程-通过点坐标生成矩形
  10. KubeCon CloudNativeCon China 2019
  11. SQL-索引-012
  12. jQuery的appendTo案例
  13. vue 本地开发时使用localhost与ip访问
  14. 关于Android 主题的那些事
  15. 菜鸟如何使用hanlp做分词的过程记录
  16. dubbo-常用配置
  17. Java 操纵XML之创建XML文件
  18. 详解Java多线程编程中LockSupport类的线程阻塞用法
  19. vs下C++内存泄露检测
  20. CSharp程序员学Android开发---3.Android内部元素不填充BUG

热门文章

  1. codeforces 442C C. Artem and Array(贪心)
  2. bzoj-3444 3444: 最后的晚餐(组合数学)
  3. jQuery时间轴插件:jQuery Timelinr
  4. ajax请求json数据案例
  5. C#带cookie Post和Get方式发送数据,保持cookie
  6. 爆炸吧 js dom ---------&gt; boom
  7. 用于json的 .ashx 小细节
  8. R之字符串连接函数paste
  9. sqlserver数据库附加报错5120
  10. web页面的回流,认识与避免