Created
July 29, 2019 18:31
-
-
Save jomadoye/f77c0188f2291cc88ac68c6ddc349920 to your computer and use it in GitHub Desktop.
The 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
const SingletonPattern = (() => { | |
let instantiated; | |
let init = () => { | |
// singleton | |
return { | |
publicMethod: () => { | |
console.log("hello world"); | |
}, | |
publicProperty: "test" | |
}; | |
}; | |
return { | |
getInstance: () => { | |
if (!instantiated) { | |
instantiated = init(); | |
} | |
return instantiated; | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment