Last active
September 23, 2016 22:21
-
-
Save khaled0fares/17996e816e82cc2840fcca18411c589e to your computer and use it in GitHub Desktop.
Singleton pattern 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(name, yearOfBirth, job, relationship){ | |
let instance; | |
function init(){ | |
return { | |
name: name, | |
age: new Date().getFullYear() - yearOfBirth, | |
job: job, | |
relationship: relationship | |
} | |
} | |
if(!instance){ | |
instance = init(); | |
} | |
return instance; | |
})("Fares", 1993, "Software engineer", "Single"); | |
console.log(Singleton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment