Carl Danley

The Singleton Pattern

This pattern restricts instantiation of an object to a single reference thus reducing its memory footprint and allowing a "delayed" initialization on an as-needed basis. This isn't too common amongst JavaScript projects today but more common in WordPress (see Eric Mann's in-depth article here).

This article is part of a series called JavaScript Design Patterns.

Advantages

Disadvantages

Example

Additional Resources

http://robdodson.me/blog/2012/08/08/javascript-design-patterns-singleton/
http://www.dofactory.com/javascript-singleton-pattern.aspx
http://chrisiona.com/the-singleton-pattern/
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript

Other Common JS Patterns

The Module Pattern
The Revealing Module Pattern
The Singleton Pattern
The Observer Pattern
The Mediator Pattern
The Prototype Pattern
The Facade Pattern
The Factory Pattern