Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document a function returned by a function using JSDoc

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'); 
like image 240
Aminadav Glickshtein Avatar asked May 03 '15 09:05

Aminadav Glickshtein


People also ask

What is JSDoc comment?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.

Can you return a function in JavaScript?

JavaScript functions can return a single value. To return multiple values from a function, you can pack the return values as elements of an array or as properties of an object.

What is JSDoc in Nodejs?

JSDoc is an open source API documentation generator for Javascript. It allows developers to document their code through comments.


1 Answers

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; } 
like image 144
SGD Avatar answered Sep 20 '22 22:09

SGD