Created
August 25, 2020 17:16
-
-
Save ishwarrimal/216a5a658d4417bc55024e1adb12c39c to your computer and use it in GitHub Desktop.
implementing singleton in a simple way in JS
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
{ | |
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