JSDoc 中文网

语法

¥Syntax

@module [[{<type>}] <moduleName>]

在 JSDoc 3.3.0 及更高版本中,<moduleName> 可能包含 module: 前缀。在以前的版本中,你必须省略此前缀。

¥In JSDoc 3.3.0 and later, <moduleName> may include the module: prefix. In previous versions, you must omit this prefix.

注意:如果你提供类型,则还必须提供名称。

¥Note: If you provide a type, you must also provide a name.

概述

¥Overview

@module 标记将当前文件标记为其自己的模块。除非另有说明,否则文件中的所有符号均假定为模块的成员。

¥The @module tag marks the current file as being its own module. All symbols in the file are assumed to be members of the module unless documented otherwise.

使用 "module:moduleName" 链接到模块(例如,在 @link@see 标签内)。例如,可以使用“{@link module:foo/bar}”链接到 "@module foo/bar"。

¥Link to a module (e.g. within a @link or @see tag) using "module:moduleName". For example, "@module foo/bar" can be linked to using "{@link module:foo/bar}".

如果未提供模块名称,则它是从模块的路径和文件名派生的。例如,假设我有一个文件 test.js,位于 src 目录中,其中包含块注释 /** @module */。以下是运行 JSDoc 的一些场景以及 test.js 的生成模块名称:

¥If the module name is not provided, it is derived from the module's path and filename. For example, suppose I have a file test.js, located in the src directory, that contains the block comment /** @module */. Here are some scenarios for running JSDoc and the resulting module names for test.js:

如果未提供,则派生模块名称。
# from src/
jsdoc ./test.js   # module name 'test'

# from src's parent directory:
jsdoc src/test.js # module name 'src/test'
jsdoc -r src/     # module name 'test'

示例

¥Examples

以下示例显示了模块中用于符号的名称路径。第一个符号是模块私有的,或 "内," 变量 - 它只能在模块内访问。第二个符号是由模块导出的静态函数。

¥The following example shows the namepaths that are used for symbols in a module. The first symbol is a module-private, or "inner," variable--it can be only accessed within the module. The second symbol is a static function that is exported by the module.

@module 的基本使用
/** @module myModule */

/** will be module:myModule~foo */
var foo = 1;

/** will be module:myModule.bar */
var bar = function() {};

当导出的符号被定义为 module.exportsexportsthis 的成员时,JSDoc 会推断该符号是模块的静态成员。

¥When an exported symbol is defined as a member of module.exports, exports, or this, JSDoc infers that the symbol is a static member of the module.

在以下示例中,Book 类被记录为静态成员 "模块:书架.书籍",以及一个实例成员 "模块:书架.Book#title"。

¥In the following example, the Book class is documented as a static member, "module:bookshelf.Book", with one instance member, "module:bookshelf.Book#title".

将导出符号定义为 'this' 的成员
/** @module bookshelf */
/** @class */
this.Book = function (title) {
    /** The title. */
    this.title = title;
};

在以下示例中,两个函数的名称路径为 "模块:颜色/混合器.混合" 和 "模块:颜色/mixer.darken"。

¥In the following example, the two functions have the namepaths "module:color/mixer.blend" and "module:color/mixer.darken".

将导出符号定义为 'module.exports' 或 'exports' 的成员
/** @module color/mixer */
module.exports = {
    /** Blend two colours together. */
    blend: function (color1, color2) {}
};
/** Darkens a color. */
exports.darken = function (color, shade) {};

更多示例请参见 记录 JavaScript 模块

¥See Documenting JavaScript Modules for further examples.