Revision: 18983
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 13, 2009 20:14 by peta
Initial Code
// 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() {}, ... };
Initial URL
Initial Description
Initial Title
3 ways of implementing the Singleton pattern in JavaScript
Initial Tags
Initial Language
JavaScript