Skip to content

Instantly share code, notes, and snippets.

@chiro-hiro
Created March 9, 2020 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiro-hiro/4cb0299ddc77dda78b3be7000aaaf95f to your computer and use it in GitHub Desktop.
Save chiro-hiro/4cb0299ddc77dda78b3be7000aaaf95f to your computer and use it in GitHub Desktop.
class Foo {
constructor() {
this.constructedAt = (new Date()).toDateString();
}
static getInstance() {
this.foo = 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