documentcloud/underscore — pull request #604 by perfectworks (2012-05-17 12:29:34+00:00)
Title: ADD: _.singleton

_.singleton

Return a singleton factory for a given class constructor.

example:

var num = 0;

var Foo = function () {
this.num = num ++;
}

var Singleton = _.singleton(Foo);

var foo1 = Singleton.getInstance();
var foo2 = Singleton.getInstance();

foo1 === foo2; // true
foo1.num === 0; // true
foo1.constructor === Foo; // true

P.S underscore.min.js & doc were not generated for this change.