danvdende
danvdende

Reputation: 245

Preventing global variables in jsdoc output

I'm currently documenting my JS files with jsdoc, but I'm running into some trouble. I have 2 files, file1.js and file2.js (not their real names obviously). Both these files contain a number of functions which I have documented in jsdoc style. When I run jsdoc on both files simultaneously, the output is a list of global functions with their descriptions. There is no distinction between where the functions are actually located (be it in file1.js or file2.js). Is there any way I can create this distinction in order to give my documentation a better structure?

Upvotes: 4

Views: 2604

Answers (1)

Louis
Louis

Reputation: 151401

You can use the @module tag in each file:

/**
 * @module file1
 */

You'd use file2 for your other file. I've assumed your modules would have the same name as your files.

Then when you want to refer to things that are in a module, you use the module: notation. So if your file1 module contains a class named foo. You'd refer to it to note the type of data a function in another module returns with @returns {module:file1~foo}. The tilde notation is explained here. It just indicates that foo is an "inner" member of the module file1. (Making it a "static" member would be better in my opinion but the current version of jsdoc does not handle it well for modules.)

Upvotes: 6

Related Questions