La finalidad del patrón de diseño Singleton es garantizar que una clase tiene sólo una instancia y proporcionar un punto de acceso global a ella.
Un ejemplo:
var PlasmikSingleton = (function() {
var instance = null;
function initialize() {
var url = "http://www.plasmik.com";
this.getUrl = function() {
return url;
}
}
return new function() {
this.getInstance = function() {
if (instance == null) {
instance = new initialize();
instance.constructor = null;
}
return instance;
}
}
})();
var singleton = PlasmikSingleton.getInstance();
alert("URL -> "+singleton.getUrl());










