Created
March 9, 2020 03:52
-
-
Save chiro-hiro/891118c4613427d9c1fce283699adac8 to your computer and use it in GitHub Desktop.
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 Foo { | |
constructor() { | |
this.constructedAt = (new Date()).toISOString(); | |
} | |
static getInstance() { | |
if (typeof this.instance === 'undefined') { | |
this.instance = new Foo(); | |
} | |
return this.instance; | |
} | |
getValue() { | |
return this.constructedAt; | |
} | |
} | |
setTimeout(function () { | |
const foo1 = Foo.getInstance(); | |
console.log(foo1); | |
}, 1000); | |
setTimeout(function () { | |
const foo2 = Foo.getInstance(); | |
console.log(foo2); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment