How to define Singleton in TypeScript -


what best , convenient way implement singleton pattern class in typescript? (both , without lazy initialisation).

singleton classes in typescript anti-pattern. can use namespaces instead.

useless singleton pattern

class singleton {     /* ... lots of singleton logic ... */     public somemethod() { ... } }  // using var x = singleton.getinstance(); x.somemethod(); 

namespace equivalent

namespace singleton {     export function somemethod() { ... } } // usage singleton.somemethod(); var x = singleton; // if need alias reason 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -