The Singleton Pattern
August 8, 2014

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

  • Reduced memory footprint
  • Single point of access
  • Delayed initialization that prevents instantiation until required

Disadvantages

  • Once instantiated, they're hardly ever "reset"
  • Harder to unit test and sometimes introduces hidden dependencies

Example

Additional Resources

Other Common JS Patterns