Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.