Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  6] [ 5]  / answers: 1 / hits: 27973  / 9 Years ago, sun, may 3, 2015, 12:00:00

I am using JSDoc for parameter documentation.



It is clear how to document the parameter types for many_prompts, but what is the right way to document the function it returns?



/**
* @param {Number} - number of times to prompt
* @return {Function(prompt{Number})} - the returned function
*/
function many_prompts(count) {
return function(prompt) {
for(var i=0; i < count; i++) alert(prompt);
}
}


//Example of use:
var y =many_prompts(3);
y('Hello World');

More From » jsdoc

 Answers
44

The way I prefer:


/**
* @param {number} count - number of times to prompt
* @returns { (prompt: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;
}

[#66772] Friday, May 1, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gabriellagiselc

Total Points: 654
Total Questions: 99
Total Answers: 106

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
;