DEV Community

Discussion on: Singleton Pattern in JavaScript

Collapse
 
mburszley profile image
Maximilian Burszley

Not sure this is a Singleton at all, just an immutable instance due to a closure creating pseudo-private members.

A Singleton indicates you can only ever have one instance of an object. Every new Http(args) would be a reference to the same thing.

Collapse
 
hi_artem profile image
Artem

This assumption is correct. That said, you should not use new keyword with this pattern. You can add a function to explicitly initialize singleton, and it would look more like traditional "Java" singleton. I don't think the latter is necessary though.