Document CommonJS Modules
Table of Contents
- Document a Simple CommonJS Module
- Document Members Assigned to module.exports
- Document Members Exported on the Module's this Object
- Document a Function that returns an AMD Module
- Document a Module as a Constructor
- Document Multiple AMD Modules Defined in a Single File
Document a Simple CommonJS Module
Add a single
@module <module identifier> tag at the top of the file that defines your module and any documented members of the
in that file will automatically be included in the documentation for that module.
Document Members Assigned to
In a Node.js module, you can assign an object literal to
module.exports directly. This pattern is automatically supported by JSDoc 3.
Document Members Exported on the Module's
JSDoc 3 understands the convention of exporting properties and functions when they are assigned to the module's
this object, as shown below.
Document a Function that returns an AMD Module
Modules can also be written using the Asynchronous Module Definition (AMD) API, which is implemented
by libraries such as RequireJS. The AMD format provides a
define method that allows you to write a function to
return a module object. Use the @exports tag to document that all the members of an object literal should be documented as members
of a module.
Document a Module as a Constructor
The following examples illustrate patterns for documenting modules that are constructors.
The same pattern can be documented in CommonJS environments.
Document Multiple AMD Modules Defined in a Single File
If you have multiple calls to
define in a single file use the @exports tag to document each function that returns module
code. Name the exported objects "exports" and JSDoc 3 will automatically document any of their members as members of their module.