How to document a function returned by a function using JSDoc
This seems to be working for me.
/**
* @param {Number} count - number of times to prompt
* @return {function(): void} - the returned function
*/
manyPrompts(count) {
/**
* My inner function
*
* @param {object} prompt Some parameter
*/
const inner = function(prompt) {
for (let i=0; i < count; i++) {
alert(prompt);
};
};
return inner;
}
You can document the inner function and then reference it like so
/**
* @param {Number} - number of times to prompt
* @return {many_prompts~inner} - the returned function
*/
function many_prompts(count){
/**
* My inner function
*
* @param {object} prompt Some parameter
*/
var inner = function(prompt){
for(var i=0;i<count;i++) alert(prompt)
};
return inner;
}
The way I prefer:
/**
* @param {number} count - number of times to prompt
* @returns { (promt:string) => void } - the returned function
*/
manyPrompts(count) {
/**
* My inner function
*
* @param {object} prompt Some parameter
*/
const inner = function(prompt) {
for (let i=0; i < count; i++) {
alert(prompt);
};
};
return inner;
}