Skip to content

Instantly share code, notes, and snippets.

@emyann
Created January 17, 2018 19:26
Show Gist options
  • Save emyann/d54372d921350c1de19e89542c622c84 to your computer and use it in GitHub Desktop.
Save emyann/d54372d921350c1de19e89542c622c84 to your computer and use it in GitHub Desktop.
ES6 Singleton
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