Skip to content

Instantly share code, notes, and snippets.

@ansarisufiyan777
Last active September 2, 2019 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ansarisufiyan777/6e10e2bda38e6953ec9ec2ab6a702928 to your computer and use it in GitHub Desktop.
Save ansarisufiyan777/6e10e2bda38e6953ec9ec2ab6a702928 to your computer and use it in GitHub Desktop.
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