singletonify

0.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i singletonify

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • cljames