Singletone
Powerful and easy to use JavaScript implementation of the Singleton design pattern. It creates singleton instance which nobody can to change or replace. Now it supports Node.js (CommonJS modules) only, but frontend support needed (AMD, etc.). Help wanted.
Install
npm i --save singletone
Examples
var singletone = ; { // save the instance local variable for the moment var singletonInstance = ; // rewrite our singleton constructor Player = singletonInstanceconstructor; // add some instance properties thisstatus = "stopped"; // return singleton instance return singletonInstance;} Playerprototype { thisstatus = "playing";}; Playerprototype { thisstatus = "stopped";}; var player = ; player; console;// "playing" var player2 = ; console;// "playing"
For more information and examples look at the tests.
Contribution
If you want to send some PR, checkout develop
branch please. It contains the latest commits.