3 ms·
Theres really no point in using the classical singleton pattern in JS since most applications have a top-level namespace object. The module pattern is actually
by Androsynth 15y ago
Theres really no point in using the classical singleton pattern in JS since most applications have a top-level namespace object. The module pattern is actually a superior singleton pattern as you have written it.
SingletonTest.getInstance() assumes SingletonTest is globally visible (or at least in the scope you care about), so therefore to call some method you do SingletonTest.getInstance().someMethod(). This is polluting the global namespace. Instead you can use the module pattern and use a global top-level namespace object: App.moduleObject.someMethod(). This is cleaner, requires less code and won't pollute the global namespace.
just say no to classical patterns in js