Last active
September 2, 2019 11:49
-
-
Save ansarisufiyan777/6e10e2bda38e6953ec9ec2ab6a702928 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
exports.RunSingleton = function () { | |
Printer = (() => { | |
let instance = null; | |
function createPrinter() { | |
function print() { | |
console.log("Print function", this); | |
} | |
function stop() { | |
console.log("Stop printer", this); | |
} | |
return { | |
print: print, | |
stop: stop | |
} | |
} | |
function getInstance() { | |
if (!instance) { | |
instance = createPrinter(); | |
} | |
return instance; | |
} | |
return { | |
getInstance: getInstance | |
} | |
})(); | |
var printerInstance = Printer.getInstance(); | |
printerInstance.print() | |
printerInstance.stop() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment