Skip to content

Instantly share code, notes, and snippets.

@tynrare
Last active February 15, 2020 09:34
Show Gist options
  • Save tynrare/c1ffcae83cb0eff1dc44812bdac4aab5 to your computer and use it in GitHub Desktop.
Save tynrare/c1ffcae83cb0eff1dc44812bdac4aab5 to your computer and use it in GitHub Desktop.
JavaScript Singletone ES6 linted template
/**
* @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