问一个TS的基础问题(单例模式基类)

哈哈哈哈哈,很快这个帖子就开始追求压行了

export class Singleton {
    /**
     * 使用示例看下面
     * @param this 
     */
    public static getInstance<T>(this: new () => T): T {
        if(!(<any>this).instance){
            (<any>this).instance = new this();
        }
        return (<any>this).instance;
    }
}

// 示例s
// 
//
// export class TestSingletonMgr extends Singleton {
//     testShow() {
//         console.log("这是继承单例的调用显示")
//     }
// }
//
// 
//  TestSingletonMgr.getInstance().testShow()
//  

其实,单例的写法早就淘汰了,还谈什么优雅 :laughing:

就是就是 纠结来纠结去也就几行代码能叫优雅吗 :joy:

代码最好是看一眼就能看懂好些吧,,