JavaScript Design Patterns: Singleton | Joe Zim's JavaScript BlogJoe Zim's JavaScript Blog | javascript singleton design pattern | Scoop.it

In JavaScript, the singleton is extremely simple and could possibly be excluded from the designation of singleton, but it does technically work similarly to a singleton, so it’s still useful to know. The singleton groups code into a single object so that you don’t need to instantiate a new one object whenever you need its resources, which allows you to have global access to those resources.

In JavaScript, the singleton is used mostly for namespacing and reducing the number of global variables that your application creates. This pattern is probably more useful in JavaScript than in any other language due to the high risk of using global variables in your code and the singleton’s ability to namespace those variables.