1 Star 1 Fork 1

MrMriacle/ts_design_mode

forked from 驯鹿者/ts_design_mode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
simpleFactory.js 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
404_already_found 提交于 2019-05-23 20:44 +08:00 . update
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var GunType;
(function (GunType) {
GunType[GunType["AK"] = 0] = "AK";
GunType[GunType["M4A1"] = 1] = "M4A1";
})(GunType || (GunType = {}));
// interface Shootable {
// shoot();
// }
var Gun = /** @class */ (function () {
function Gun() {
}
return Gun;
}());
var AK47 = /** @class */ (function (_super) {
__extends(AK47, _super);
function AK47() {
return _super !== null && _super.apply(this, arguments) || this;
}
//具体产品 - AK47
AK47.prototype.shoot = function () {
console.log("ak47 shoot.");
};
return AK47;
}(Gun));
var M4A1 = /** @class */ (function (_super) {
__extends(M4A1, _super);
function M4A1() {
return _super !== null && _super.apply(this, arguments) || this;
}
//具体产品 - M4A1
M4A1.prototype.shoot = function () {
console.log("m4a1 shoot.");
};
return M4A1;
}(Gun));
var GunFactory = /** @class */ (function () {
function GunFactory() {
}
GunFactory.createGun = function (type) {
switch (type) {
case GunType.AK:
return new AK47();
case GunType.M4A1:
return new M4A1();
default:
throw Error("not support this gun yet");
}
};
return GunFactory;
}());
GunFactory.createGun(GunType.AK).shoot();
GunFactory.createGun(GunType.M4A1).shoot();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mrmriacle/ts_design_mode.git
git@gitee.com:mrmriacle/ts_design_mode.git
mrmriacle
ts_design_mode
ts_design_mode
master

搜索帮助