Mr.Yuan Mr.Yuan

苟正其身矣,于从政乎何有?不能正其身,如正人何?

目录
Typescript 小工具 ---- 单例能用类
/    

Typescript 小工具 ---- 单例能用类

typescript 通用单例类

export function Singleton<E>() {
    class SingletonE {
        protected constructor() {}
        private static _ins: SingletonE = null;
        public static get Ins(): E {
            if (SingletonE._ins == null) SingletonE._ins = new this();
            return SingletonE._ins as E;
        }
    }
    return SingletonE;
}

标题:Typescript 小工具 ---- 单例能用类
作者:K
地址:https://pala.icu/articles/2021/09/02/1630593040230.html