DEV Community

Discussion on: Singleton Pattern in JavaScript?

Collapse
 
devdufutur profile image
Rudy Nappée

Not sure you can have a private constructor in js...

That said, you don't really need singletons in JS... Using functions inside es6 modules do the exact same job (you can even store a state inside modules).

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

You can have a private constructor in TypeScript. But all is lost when transpiled down to JavaScript.