Created
January 17, 2018 19:26
-
-
Save emyann/d54372d921350c1de19e89542c622c84 to your computer and use it in GitHub Desktop.
ES6 Singleton
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
class ImmutableClass { | |
constructor() { | |
// return value from class constructor | |
return createInstance() | |
} | |
} | |
let instance = null; | |
function createInstance() { | |
if(instance === null){ | |
instance = Object.create(ImmutableClass.prototype); | |
instance.someData = {} | |
} | |
} | |
(new ImmutableClass()) === (new ImmutableClass()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment