Skip to content

Instantly share code, notes, and snippets.

@abdalla
Created February 3, 2021 14:07
Show Gist options
  • Save abdalla/f83dc50d550d2fee9cefe682e03ecd1b to your computer and use it in GitHub Desktop.
Save abdalla/f83dc50d550d2fee9cefe682e03ecd1b to your computer and use it in GitHub Desktop.
Singleton - Pattern
"use strict";
var Singleton = (function () {
function ProcessManager() {
this.numProcess = 0;
}
var processManager = undefined;
var createProcessManager = function createProcessManager() {
processManager = new ProcessManager();
};
return {
getProcessManager: function getProcessManager() {
if (!processManager) {
createProcessManager();
}
return processManager;
}
};
})();
var pm = Singleton.getProcessManager();
var pm2 = Singleton.getProcessManager();
console.log(pm === pm2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment