2
0
mirror of synced 2025-01-11 14:44:12 +00:00

36 lines
633 B
JavaScript
Raw Normal View History

2017-03-02 13:10:10 +00:00
const Symbol = require('es6-symbol');
class Singleton {
constructor() {
const Class = this.constructor;
if (!Class[this.singleton]) {
Class[this.singleton] = this;
}
return Class[this.singleton];
}
static get instance() {
if (!this[this.singleton]) {
this[this.singleton] = new this();
}
return this[this.singleton];
}
static set instance(instance) {
this[this.singleton] = instance;
return this[this.singleton];
}
static get singleton() {
return Symbol(this.namespace);
}
static reset() {
delete this[this.singleton];
}
}
export default Singleton;