Singleton.ts 390 B

1234567891011121314
  1. export function Singleton<T>() {
  2. class SingletonT {
  3. protected constructor() {}
  4. private static _Instance: SingletonT|null = null;
  5. public static get Instance(): T {
  6. if(SingletonT._Instance == null) {
  7. SingletonT._Instance = new this();
  8. }
  9. return SingletonT._Instance as T;
  10. }
  11. }
  12. return SingletonT;
  13. }