Answers for "typescript singleton"

1

typescript singleton

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;
Posted by: Guest on May-30-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language