语法
¥Syntax
-
@memberof <parentNamepath>
-
@memberof! <parentNamepath>
概述
¥Overview
@memberof 标记标识属于父符号的成员符号。
¥The @memberof tag identifies a member symbol that belongs to a parent symbol.
默认情况下,@memberof 标记将成员符号记录为静态成员。对于内部成员和实例成员,你可以在名称路径后使用范围标点符号,也可以添加 @inner 或 @instance 标记。
¥By default, the @memberof tag documents member symbols as static members. For inner and instance members, you can use scoping punctuation after the namepath, or you can add the @inner or @instance tag.
"forced" @memberof 标记 @memberof! 强制将对象记录为属于特定的父对象,即使它看起来具有不同的父对象。
¥The "forced" @memberof tag, @memberof!, forces the object to be documented as belonging to a specific parent even if it appears to have a different parent.
示例
¥Examples
在以下示例中,hammer
函数通常会记录为全局函数。这是因为,事实上,它是一个全局函数,但它也是 Tools
命名空间的成员,这就是你希望记录它的方式。解决方案是添加@memberof 标签:
¥In the following example, the hammer
function would normally be documented as a global function.
That's because, in fact, it is a global function, but it is also a member of the Tools
namespace,
and that's how you wish to document it. The solution is to add a @memberof tag:
/** @namespace */
var Tools = {};
/** @memberof Tools */
var hammer = function() {
};
Tools.hammer = hammer;
对于类的实例成员,请使用语法 "@memberof ClassName.prototype" 或 "@memberof ClassName#"。或者,你可以将 "@memberof ClassName" 与 "@instance" 标签组合起来。
¥For instance members of a class, use the syntax "@memberof ClassName.prototype" or "@memberof ClassName#". Alternatively, you can combine "@memberof ClassName" with the "@instance" tag.
/** @class Observable */
create(
'Observable',
{
/**
* This will be a static member, Observable.cache.
* @memberof Observable
*/
cache: [],
/**
* This will be an instance member, Observable#publish.
* @memberof Observable.prototype
*/
publish: function(msg) {},
/**
* This will also be an instance member, Observable#save.
* @memberof Observable#
*/
save: function() {},
/**
* This will also be an instance member, Observable#end.
* @memberof Observable
* @instance
*/
end: function() {}
}
);
以下示例使用强制 @memberof 标记 "@memberof!" 来记录作为类 (Data) 实例成员的对象 (Data#point) 的属性。
¥The following example uses the forced @memberof tag, "@memberof!", to document a property of an object (Data#point) that is an instance member of a class (Data).
当你使用 @property 标记来记录属性时,你无法使用其长名称链接到该属性。我们可以通过使用 "@alias" 和 "@memberof!" 来强制属性可链接,以告诉 JSDoc Data#point.y 应记录为 "数据#" 的成员 "point.y",而不是 "数据#" 的 "point" 的成员 "y"。
¥When you use the @property tag to document a property, you cannot link to the property using its longname. We can force the property to be linkable by using "@alias" and "@memberof!" to tell JSDoc that Data#point.y should be documented as a member "point.y" of "Data#", rather than a member "y" of "point" of "Data#".
/** @class */
function Data() {
/**
* @type {object}
* @property {number} y This will show up as a property of `Data#point`,
* but you cannot link to the property as {@link Data#point.y}.
*/
this.point = {
/**
* The @alias and @memberof! tags force JSDoc to document the
* property as `point.x` (rather than `x`) and to be a member of
* `Data#`. You can link to the property as {@link Data#point.x}.
* @alias point.x
* @memberof! Data#
*/
x: 0,
y: 1
};
}