JSDoc 中文网

语法

🌐 Syntax

概述

🌐 Overview

@memberof 标记标识属于父符号的成员符号。

🌐 The @memberof tag identifies a member symbol that belongs to a parent symbol.

默认情况下,@memberof 标签将成员符号记录为静态成员。对于内部和实例成员,你可以在 namepath 后使用作用域标点,或者你可以添加 @内部@实例 标签。

🌐 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.

“强制” @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:

使用 @memberof
/** @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.

在类原型中使用 @memberof
/** @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#point) 的属性,该属性是类 (Data) 的实例成员。

🌐 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 标签来记录一个属性时,不能通过其 longname 来链接该属性。我们可以通过使用 "@alias" 和 "@memberof!" 强制该属性可链接,以告诉 JSDoc 将 Data#point.y 记录为 Data# 的成员 "point.y",而不是 Data# 的 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#".

为对象属性使用 @memberof!
/** @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
    };
}