Table of Contents
- Module identifiers
- Function that returns an object literal
- Function that returns another function
- Module declared in a return statement
- Module object passed to a function
- Multiple modules defined in one file
- Related Links
JSDoc 3 makes it possible to document modules that use the Asynchronous Module Definition (AMD) API, which is implemented by libraries such as RequireJS. This page explains how to document an AMD module for JSDoc, based on the coding conventions that your module uses.
If you’re documenting CommonJS or Node.js modules, see CommonJS Modules for instructions.
When you document an AMD module, you’ll use an
@exports tag or
@module tag to document the identifier that’s passed to the
require() function. For example, if users load the module by calling
require('my/shirt', /* callback */), you’ll write a JSDoc comment that contains the tag
@exports my/shirt or
@module my/shirt. The examples below can help you decide which of these tags to use.
If you use the
@module tag without a value, JSDoc will try to guess the correct module identifier based on the filepath.
When you use a JSDoc namepath to refer to a module from another JSDoc comment, you must add the prefix
module:. For example, if you want the documentation for the module
my/pants to link to the module
my/shirt, you could use the
@see tag to document
my/pants as follows:
/** * Pants module. * @module my/pants * @see module:my/shirt */
Similarly, the namepath for each member of the module will start with
module:, followed by the module name. For example, if your
my/pants module exports a
Jeans constructor, and
Jeans has an instance method named
hem, the instance method’s longname is
Function that returns an object literal
If you define your AMD module as a function that returns an object literal, use the
@exports tag to document the module’s name. JSDoc will automatically detect that the object’s properties are members of the module.
Function that returns another function
If you define your module as a function that exports another function, such as a constructor, you can use a standalone comment with a
@module tag to document the module. You can then use an
@alias tag to tell JSDoc that the function uses the same longname as the module.
Module declared in a return statement
If you declare your module object in a function’s
return statement, you can use a standalone comment with a
@module tag to document the module. You can then add an
@alias tag to tell JSDoc that the module object has the same longname as the module.
Module object passed to a function
If the module object is passed into the function that defines your module, you can document the module by adding an
@exports tag to the function parameter. This pattern is supported in JSDoc 3.3.0 and later.
Multiple modules defined in one file
@exports tag to document each module object.
Using namepaths with JSDoc 3