- 1 :
export { WrapperObject };
- 2 :
- 3 :
/**
- 4 :
* @class
- 5 :
* @classdesc Contient une instance d'un objet, utile pour la création d'un singleton.
- 6 :
* @template {!Tt} T
- 7 :
*/
- 8 :
class WrapperObject {
- 9 :
/**
- 10 :
* Instance de la classe
- 11 :
* @private
- 12 :
* @type {?T}
- 13 :
*/
- 14 :
#_instance = null;
- 15 :
/**
- 16 :
* Arguments par défaut
- 17 :
* @private
- 18 :
* @type {?{TypeOfItem: typeof T, args:any[]}}
- 19 :
*/
- 20 :
#_args = null;
- 21 :
- 22 :
/**
- 23 :
* Constructeur de la classe
- 24 :
* @param {typeof T} TypeOfItem Classe
- 25 :
* @param {...any} args Argument pour instancier la classe
- 26 :
*/
- 27 :
constructor(TypeOfItem, ...args) {
- 28 :
this.#_args = {
- 29 :
TypeOfItem,
- 30 :
args,
- 31 :
};
- 32 :
}
- 33 :
- 34 :
/**
- 35 :
* Renvoie un instance de classe
- 36 :
* @type {T}
- 37 :
* @readonly
- 38 :
*/
- 39 :
get Instance() {
- 40 :
if (!this.#_instance) {
- 41 :
const { TypeOfItem, args } = this.#_args;
- 42 :
this.#_instance = new TypeOfItem(...args);
- 43 :
this.#_args = undefined;
- 44 :
}
- 45 :
- 46 :
return this.#_instance;
- 47 :
}
- 48 :
- 49 :
/**
- 50 :
* Contient une instance d'un objet, utile pour la création d'un singleton.
- 51 :
* @static
- 52 :
* @param {typeof T} typeofitem
- 53 :
* @param {...any} args
- 54 :
* @returns {WrapperObject<T>}
- 55 :
*/
- 56 :
static Create(typeofitem, ...args) {
- 57 :
return new WrapperObject(typeofitem, ...args);
- 58 :
}
- 59 :
}