Skip to content

Instantly share code, notes, and snippets.

@jomadoye
Created July 29, 2019 18:31
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 jomadoye/f77c0188f2291cc88ac68c6ddc349920 to your computer and use it in GitHub Desktop.
Save jomadoye/f77c0188f2291cc88ac68c6ddc349920 to your computer and use it in GitHub Desktop.
The singleton pattern
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