Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to docstring a function arugument which is itself a function with arguments in JavaScript?

How can I docstring an argument which is a function itself?

Example:

/**
 * 
 * @param secondFunction // I want to say this should be a function that accepts a number
 */
function firstFunction(secondFunction) {
    const a = 1;
    secondFunction(a);
}

Cheers!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

From the JSDoc documentation:

Callback functions

If a parameter accepts a callback function, you can use the @callback tag to define a callback type, then include the callback type in the @param tag.

Parameters that accept a callback

/**
 * This callback type is called `secondFunction` and is displayed as a global symbol.
 *
 * @callback secondFunction
 * @param {number} a
 */

/**
 * executes secondFunction
 * @param {secondFunction} secondFunction - The callback
 */
function firstFunction(secondFunction) {
    const a = 1;
    secondFunction(a);
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading