Skip to content

Instantly share code, notes, and snippets.

@ishwarrimal
Created August 25, 2020 17:16
Show Gist options
  • Save ishwarrimal/216a5a658d4417bc55024e1adb12c39c to your computer and use it in GitHub Desktop.
Save ishwarrimal/216a5a658d4417bc55024e1adb12c39c to your computer and use it in GitHub Desktop.
implementing singleton in a simple way in JS
{
let Singleton = (function(){
let instance;
let createInstance = ()=>{
let obj = {name: new Date()}
return obj;
}
return {
getInstance : () => {
if(!instance){
instance = createInstance();
}
return instance
}
}
})()
Singleton.getInstance()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment