Last active
April 27, 2017 03:24
-
-
Save aloerina01/b05699ec4e47735968b3a84ea0b8441d to your computer and use it in GitHub Desktop.
Singleton pattern with JS Module
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 Singleton from './Singleton'; | |
const config = Singleton.getInstance(); | |
console.log(config.isShowHeader); // true |
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 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