/**
 * 單例基類(要先new在使用)
 * @example
 * export default class Test extends BaseSingleton<Test>() { ...... }
 * new Test();
 * Test.Instance.Init();
 */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default function BaseSingleton<T>() {
	class BaseSingleton {
		public constructor() {
			if ((<any>this)._instance == null) {
				BaseSingleton._instance = <any>this;
			}
		}
		private static _instance: BaseSingleton = null;
		public static get Instance(): T {
			return (<any>this)._instance;
		}

		/** 銷毀 */
		public Destroy(): void {
			(<any>this)._instance = null;
		}
	}
	return BaseSingleton;
}