Created
February 3, 2021 14:07
-
-
Save abdalla/f83dc50d550d2fee9cefe682e03ecd1b to your computer and use it in GitHub Desktop.
Singleton - Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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