shabashj
4/19/2016 - 7:55 PM

Singleton design pattern

Singleton design pattern

    var Singleton = (function () {
        var instance;
     
        function createInstance() {
            var object = new Object("I am the instance");
            return object;
        }
     
        return {
            getInstance: function () {
                if (!instance) {
                    instance = createInstance();
                }
                return instance;
            }
        };
    })();
     
    function run() {
     
        var instance1 = Singleton.getInstance();
        var instance2 = Singleton.getInstance();
     
        alert("Same instance? " + (instance1 === instance2));  
    }
var WindowEventManagerSingelton = (function () {
    var instance;

    return function (win) {
        if (!instance) {
            instance = new WindowEventManager(win);
        }
        return instance;
    };
})();