1234567891011121314151617181920212223 |
- /**
- * 单例基类
- */
- export class Singleton {
- constructor() {}
- /**获取单例实例
- * @returns 单例实例
- */
- public static ins<T extends {}>(this: new () => T): T {
- if (!(<any>this)._ins) {
- ;(<any>this)._ins = new this()
- }
- return (<any>this)._ins
- }
- /**
- * 销毁单例实例
- */
- public static destroy<T extends {}>(this: new () => T): void {
- ;(<any>this)._ins = null
- }
- }
|