Created
October 13, 2009 23:36
-
-
Save peta/209657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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