常用的设计模式
`
let TankFactor = {
tankList: {
"01": function() {
const img = new Image();
img.src = "./images/01.jpg";
return img;
},
"02": function() {
const img = new Image(); // 创建一张图片
img.src = "./images/02.jpg";
return img;
},
"03": function() {
const img = new Image();
img.src = "./images/03.jpg";
return img;
},
"04": function() {
const img = new Image();
img.src = "./images/04.jpg";
return img;
}
},
create: function(type) { // 通过create来创建坦克
let info = this.tankList[type](); // this.tankList['01']
return info;
}
}
let v1 = TankFactor.create('02');
document.body.appendChild(v1);