Skip to content

Instantly share code, notes, and snippets.

@grigorkh
Created August 28, 2016 09:36
Show Gist options
  • Save grigorkh/a9dbe2ac91d0e0635517535dda009c57 to your computer and use it in GitHub Desktop.
Save grigorkh/a9dbe2ac91d0e0635517535dda009c57 to your computer and use it in GitHub Desktop.
Singleton ES6 class
let instance = null;
export class Cache{
constructor() {
if(!instance){
instance = this;
}
this.time = new Date()
return instance;
}
}
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