10

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
  • 3,880
  • 1
  • 21
  • 74

3 Answers3

2

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 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}

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.

  • There's another way I noticed here that used `` markdown to highlight the param name.

More

In case you're interested to read more:

Babak
  • 986
  • 10
  • 16
0

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
  • 281
  • 2
  • 14
  • 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