0.0.2 • Published 11 years ago
singletonify v0.0.2
singletonify
Install
npm install singletonify
Usage
var singletonify = require('singletonify');
// test function
function test (value) {
this.v = value;
}
// singletonify
var sTest = singletonify(test);
// 1
var s1 = sTest.getInstance('hello');
var s2 = new sTest('world');
var s3 = new sTest('!!!!!!');
console.log(s1 === s2);
console.log(s2 === s3);
console.log(s1.v); // hello
console.log(s2.v); // hello
console.log(s3.v); // hello
Origin
http://blog.javarouka.me/2012/02/javascripts-pattern-1-singeton-patterrn.html