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
Post a Comment