I am using the JSDoc generator to generate some good looking documentation for my project in which I am using AMD modules.
In my project I have some modules that contain functions that are not exported so they cannot be used from outside the module. When generating the JSDoc, these functions are not included in the documentation.
I created the following example module to illustrate my example:
/**
* Example foobar module
* @module foobar
*/
define([], function () {
/**
* Returns foo
* @returns {string} - The string "foo"
*/
function foo() {
return "foo";
}
return {
/**
* Returns bar
* @returns {string} - The string "bar"
*/
bar: function(){
return "bar";
}
}
});
When I generate documentation for the above module, only the bar
function is included in the documentation, whereas I would also like to have the foo
function included in my documentation and marked as private.
Is there any way to achieve this? Thanks.
I am using the JSDoc generator to generate some good looking documentation for my project in which I am using AMD modules.
In my project I have some modules that contain functions that are not exported so they cannot be used from outside the module. When generating the JSDoc, these functions are not included in the documentation.
I created the following example module to illustrate my example:
/**
* Example foobar module
* @module foobar
*/
define([], function () {
/**
* Returns foo
* @returns {string} - The string "foo"
*/
function foo() {
return "foo";
}
return {
/**
* Returns bar
* @returns {string} - The string "bar"
*/
bar: function(){
return "bar";
}
}
});
When I generate documentation for the above module, only the bar
function is included in the documentation, whereas I would also like to have the foo
function included in my documentation and marked as private.
Is there any way to achieve this? Thanks.
Share asked Nov 24, 2015 at 10:32 NiekertNiekert 9471 gold badge9 silver badges21 bronze badges1 Answer
Reset to default 6Note: This is tested on JSDoc 3
There are two parts to this:
- Get JSDoc to generate code for the nested function
- Get JSDoc to generate code for the private member
Get JSDoc to generate code for the nested function
/**
* Returns foo
* @memberOf module:foobar
* @returns {string} - The string "foo"
*/
function foo() {
return "foo";
}
By default, nested functions are not documented. To do so, add the @memberOf
directive. This forces JSDoc to document the function as a member of the module. Notice the module:
prefix - this is a standard.
This should make foo
show up as under the Methods
section of module foobar
.
Get JSDoc to generate code for the private member
Now, just mark the function as private. To do this, use the @private
directive.
/**
* Returns foo
* @private
* @memberOf module:foobar
* @returns {string} - The string "foo"
*/
function foo() {
return "foo";
}
You'll notice that the documentation now again does not contain the method foo
. This is because JSDoc ignores private members by default. To generate code for private members as well, use the -p
mand line option.
jsdoc foobar.js -p
Now foo shows up as a (private, static)
method in foobar
, while bar
is just (static)
.