The Singleton Pattern
The singleton pattern is a design pattern that is used to restrict instantiation of a class to one object.
This implementation differs from Gavins in that the user never has to initialize
it, and instead only needs to ask for it. All initialization occurs internally
in the lazy-load fashion: the first time it is requested it is internally
initialized - thereafter the original instance is always returned. See line 49
singleton.js for the lazy-load bit.
To view the demo, download the code and navigate to
demo.html in your browser.
To view the code, click on that
singleton.js file in the file list.
The Original Implementation
Gavins original implementation is here: