Skip to content

Instantly share code, notes, and snippets.

@peta
Created October 13, 2009 23:36
Show Gist options
  • Save peta/209657 to your computer and use it in GitHub Desktop.
Save peta/209657 to your computer and use it in GitHub Desktop.
// WAY 1 - Instantiating an anonymous function
var MySingleton = new (new MyClass(args));
// WAY 2 - Using an instance manager
var getMySingleton = (function(options) {
function MyClass(args) {}
var singleton;
return function(args) {
return singleton ? singleton : singleton = new MyClass(args);
}
})();
// WAY 3 - The simple way
var MySingleton = {
prop: "foo",
method: function() {},
...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment