📜  typescript singleton - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:27.504000             🧑  作者: Mango

代码示例1
class MyClass
{
    private static _instance: MyClass;

    private constructor()
    {
        //...
    }

    public static get Instance()
    {
        // Do you need arguments? Make it a regular static method instead.
        return this._instance || (this._instance = new this());
    }
}

const myClassInstance = MyClass.Instance;