JSDoc 中文网

语法

🌐 Syntax

@namespace [[{<type>}] <SomeName>]

概述

🌐 Overview

@namespace 标签表示一个对象为其成员创建命名空间。你也可以编写一个虚拟的 JSDoc 注释来定义你的代码使用的命名空间。

🌐 The @namespace tag indicates that an object creates a namespace for its members. You can also write a virtual JSDoc comment that defines a namespace used by your code.

如果命名空间由除对象字面量之外的符号定义,则可以在 @namespace 标签中包含类型表达式。如果 @namespace 标签包含类型,则它还必须包含名称。

🌐 If a namespace is defined by a symbol other than an object literal, you can include a type expression along with the @namespace tag. If the @namespace tag includes a type, it must also include a name.

你可能需要记录一个名称包含不寻常字符(例如“#”或“!”)的命名空间。在这些情况下,当你记录或链接到该命名空间时,必须在包含不寻常字符的命名空间部分周围添加引号。详细信息请参见下面的示例。

🌐 You may need to document a namespace whose name includes unusual characters, such as "#" or "!". In these cases, when you document or link to the namespace, you must add quotation marks around the portion of the namespace that includes unusual characters. See the examples below for details.

示例

🌐 Examples

在对象上使用 @namespace 标签
/**
 * My namespace.
 * @namespace
 */
var MyNamespace = {
    /** documented as MyNamespace.foo */
    foo: function() {},
    /** documented as MyNamespace.bar */
    bar: 1
};
为虚拟评论使用 @namespace 标签
/**
 * A namespace.
 * @namespace MyNamespace
 */

/**
 * A function in MyNamespace (MyNamespace.myFunction).
 * @function myFunction
 * @memberof MyNamespace
 */

如果 @namespace 包含名称中有不寻常字符的符号,则必须用双引号将该符号的名称括起来。如果符号的名称已经包含一个或多个双引号,请用前导反斜杠 () 转义双引号。

🌐 If a @namespace includes a symbol whose name has unusual characters, you must enclose the symbol's name in double quotes. If the symbol's name already contains one or more double quotes, escape the double quotes with a leading backslash (\).

使用含有不寻常成员名称的 @namespace 标签
/** @namespace window */

/**
 * Shorthand for the alert function.
 * Refer to it as {@link window."!"} (note the double quotes).
 */
window["!"] = function(msg) { alert(msg); };