Last active
February 15, 2020 09:34
-
-
Save tynrare/c1ffcae83cb0eff1dc44812bdac4aab5 to your computer and use it in GitHub Desktop.
JavaScript Singletone ES6 linted template
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
/** | |
* @file singletone_template.js | |
* @author tynrare | |
* @version 1 | |
* @module Template/Singletone | |
*/ | |
let instance = null; | |
/** | |
* Default template pattern class | |
* #singletone | |
*/ | |
export default class SingletoneTemplate { | |
/** | |
* inits fields with given properties or anything you need | |
* | |
* @private | |
*/ | |
constructor() { | |
this.field = ''; | |
//and do whatever you need | |
} | |
/** | |
* here you may add something that changes app itself and pass init arguments | |
* | |
* @param {object} properties class init properties | |
*/ | |
init(properties){ | |
this.properties = properties; | |
//dom.addElements(); //for example | |
} | |
/** | |
* Allows to get singletone instance anywhere | |
* | |
* @returns {object} this.#instance | |
* @static | |
* @public | |
*/ | |
static getInstance() { | |
if (!instance) { | |
instance = new SingletoneTemplate(); | |
} | |
return instance; | |
} | |
/** | |
* getInstance() shorthand | |
* | |
* @returns {object} this.#instance | |
* @static | |
*/ | |
static get instance() { | |
return this.getInstance(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment