语法
¥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
/**
* My namespace.
* @namespace
*/
var MyNamespace = {
/** documented as MyNamespace.foo */
foo: function() {},
/** documented as MyNamespace.bar */
bar: 1
};
/**
* 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 window */
/**
* Shorthand for the alert function.
* Refer to it as {@link window."!"} (note the double quotes).
*/
window["!"] = function(msg) { alert(msg); };