Singleton design pattern implementation which easy to use

npm install pragma-singleton
192 downloads in the last day
817 downloads in the last week
2 493 downloads in the last month

Pragma Singleton Build Status NPM version

Singleton design pattern implementation which easy to use.

Just apply this to any constructor function and all 'new' operators for this constructor will return the same instance.


To install just use NPM

npm install pragma-singleton
var singleton = require('pragma-singleton');

function Constructor(someValue) {
    this.someValue = someValue;

var SingletonConstructor = singleton(Constructor),
    instance1 = new SingletonConstructor('value1'),
    instance2 = new SingletonConstructor('value2');

console.log(instance1 == instance2); // true, because the same instance
console.log(instance2.someValue); // value1, because the value of first created instance

Pragma Dudes wish you live long and prosper.

npm loves you