//http://www.jermywells.com "use strict"; var Singleton = function () { //if (Singleton.prototype.instance) { // return Singleton.prototype.instance; //} //Singleton.prototype.instance = this; var instanceName = ""; this.setInstanceName = function (n) { instanceName = n; }; this.getInstanceName = function () { return instanceName; }; }; var firstSingleton = new Singleton(); firstSingleton.setInstanceName('first One'); var secondSingleton = new Singleton(); secondSingleton.setInstanceName('second One'); document.getElementById('first').innerHTML = firstSingleton.getInstanceName(); document.getElementById('second').innerHTML = secondSingleton.getInstanceName();
<div id="first"></div> <div id="second"></div>