Can JSDoc document dynamically generated methods?
@name
is made for this:
This tag is best used in "virtual comments" for symbols that are not readily visible in the code...
ES6:
/** Class A */
class A {
constructor () {
['Thing', 'Ball'].map((name) => {
this['print' + name] = (N) => {
let i = 0;
while (i < N) {
console.log(name);
i++;
}
};
});
}
}
/**
* @name A#printThing
* @function
* @memberof A
* @description Prints 'Thing'
* @param {Number} N - The number of times to print.
*/
/**
* @name A#printBall
* @function
* @memberof A
* @description Prints 'Ball'
* @param {Number} N - The number of times to print.
*/
ES5:
/**
* @class A
*/
var A = function () {
var me = this;
var registerPrinter = function (name) {
me['print' + name] = function (N) {
var i = 0;
while (i < N) {
console.log(name);
i++;
}
};
};
['Thing', 'Ball'].map(registerPrinter);
/**
* @name A#printThing
* @function
* @memberof A
* @description Prints 'Thing'
* @param {Number} N - The number of times to print.
*/
/**
* @name A#printBall
* @function
* @memberof A
* @description Prints 'Ball'
* @param {Number} N - The number of times to print.
*/
}