Created
August 28, 2016 09:36
-
-
Save grigorkh/a9dbe2ac91d0e0635517535dda009c57 to your computer and use it in GitHub Desktop.
Singleton ES6 class
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
let instance = null; | |
export class Cache{ | |
constructor() { | |
if(!instance){ | |
instance = this; | |
} | |
this.time = new Date() | |
return instance; | |
} | |
} |
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
import {Cache} from './class.js'; | |
let cache = new Cache(); | |
console.log(cache.time); | |
setTimeout(function() { | |
let cache = new Cache(); | |
console.log(cache.time); | |
},4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment