Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class Foo {
constructor() {
this.constructedAt = (new Date()).toDateString();
static getInstance() { = 1;
this.instance = this;
return this.instance;
getValue() {
return this.constructedAt;
const foo1 = Foo.getInstance();
const foo2 = Foo.getInstance();
console.log(foo1, foo2);
console.log(foo1 === foo2, foo1.getValue());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.