Skip to content

Instantly share code, notes, and snippets.

@aloerina01
Last active April 27, 2017 03:24
Show Gist options
  • Save aloerina01/b05699ec4e47735968b3a84ea0b8441d to your computer and use it in GitHub Desktop.
Save aloerina01/b05699ec4e47735968b3a84ea0b8441d to your computer and use it in GitHub Desktop.
Singleton pattern with JS Module
import Singleton from './Singleton';
const config = Singleton.getInstance();
console.log(config.isShowHeader); // true
class Singleton {
constructor() {
this.init();
}
init() {
// fetch values
this._showHeader = true;
this._pattern = 101;
}
get isShowHeader() {
return this._showHeader;
}
get pattern() {
return this._pattern;
}
}
const instance = new Singleton();
function getInstance(val) {
return instance;
}
export default { getInstance };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment