12

I am new to using JSDocs and couldn't find an answer to this question.

Suppose I wanted to write this simple function:

function hasQ(array, item) {return array.includes(item);}

which with JSDoc's I would mark-up like:

/**
* Another way to call array.includes(item);
* @param {Array} array
* @param {*} item to test if contained in array
* @returns
*/

Is there a way for me to markup the word array in the second @param statement such that it references the first @param?

This is just a toy example, but I hope it makes the concept clear.

SumNeuron
  • 4,850
  • 5
  • 39
  • 107

3 Answers3

7

Cross-Reference Parameters

Regarding @param as far as I know, there's no way to cross-reference parameters. As suggested here you can use plain English.

As a partial solution, you can use markdown's backticks to highlight the param name (as described here), for example:

/**
 * @param {*} item to test if contained in `array`
 */

Sidenote: Reference External

There's a concept of inline @link to external resources in JSDoc that I guess would be useful here. You can make it clear in your description that for example your talking about the function includes of Array:

/**
* Another way to call [Array's includes function]{@link external:Array#includes}
* @param {Array} array
* @param {*} item to test if contained in array
* @returns
*/
function hasQ(array, item) {
    return array.includes(item);
}

Or if you prefer a link without a text, just remove the part inside [] in the first line:

/**
 * Another way to call {@link external:Array#includes}
 */

Read More

In case you're interested to read more:

maxkoryukov
  • 4,205
  • 5
  • 33
  • 54
Babak
  • 1,274
  • 15
  • 18
2

There is no way to do that. Source: https://github.com/jsdoc/jsdoc/issues/1145

-2

I did not see the possibility of writing related parameters (but see parameters with properties). But you can write description ;)

/**
 * @method
 * @param {Array} array - description for this param
 * @param {*} item - description for this param
 * @description Please write your description for Method
 * @returns {*|boolean}
 */
const hasQ = (array, item) => array.includes(item);
Valera Checha
  • 294
  • 4
  • 16
  • 1
    While the answer is technically correct, it is written quite confusingly, probably a language issue. I'm not being picky but I had to read it many times until I got it was saying the same as the answer I posted. – Hernán Pentimalli Aug 24 '20 at 20:03