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 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 类被记录为一个静态成员,“module:bookshelf.Book”,并具有一个实例成员,“module:bookshelf.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;
};

在以下示例中,这两个函数的名称路径分别是“module:color/mixer.blend”和“module:color/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.