Using JSDoc, how do I document this code?
var mynamespace = {};
/**
* What do I put here?
*/
mynamespace.myfunc = (function () {
var i = 0;
/**
* Do I need to put anything here?
*/
return function (a) {
return a + i++;
};
}());
The signature in this case could be:
/**
* @param {Number} base
* @return {Number}
*/
I'm using the Google Closure Compiler and it doesn't like JSDoc near return function () {. I'm guessing there must be a proper way to do this. I guess my real question is: "how do I shut up GCC?" :p
I looked around a bit but I didn't find this situation exactly. I would imagine it's quite common.
I'm not a JSDoc pro but I could suggest you something
First I suggest initializing the i variable to 0 to not have a NaN value return by your function. But that's just details of the code and not relevant for your question about commenting according to JSDoc.
Maybe you should organize your code this way to "shut up" GCC :
var mynamespace = {};
/**
* Display the value we pass with a counter incremented each time we call the method
* @name myFunc
* @params {Number} a - value to add to the counter
* @return {Number} addition of a and i++
*/
mynamespace.myfunc = (function () {
var i;
/**
* @alias myFunc
*/
function add(a) {
return a + i++;
};
return add;
}());
It could be because you return an anonymous function.
Hope it helps.
EDIT :
I found out that the @alias tag could make the deal. Maybe you can try with the code I edited in the code snippet.
More details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With