JSDoc 中文网

概述

¥Overview

使用 @instance 标签会将符号标记为其父符号的实例成员。这意味着它可以被 "Parent#Child" 引用。

¥Using the @instance tag will mark a symbol as an instance member of its parent symbol. This means it can be referred to by "Parent#Child".

使用 @instance 将覆盖 doclet 的默认范围(除非它位于全局范围内,在这种情况下它将保持全局)。

¥Using @instance will override a doclet's default scope (unless it is in the global scope, in which case it will remain global).

示例

¥Examples

以下示例是 "@function MyNamespace#myFunction" 的书写方式:

¥The following example is a longhand way of writing "@function MyNamespace#myFunction":

使用 @instance 使虚拟 doclet 成为实例成员
/** @namespace MyNamespace */
/**

 * myFunction is now MyNamespace#myFunction.

 * @function myFunction

 * @memberof MyNamespace

 * @instance
 */

更有用的是,你可以使用 @instance 标记来覆盖 JSDoc 推断的范围。例如,你可以指示将静态成员用作实例成员:

¥More usefully, you can use the @instance tag to override the scope that JSDoc infers. For example, you can indicate that a static member is used as an instance member:

使用@instance 来标识实例成员
/** @namespace */
var BaseObject = {
    /**

     * foo is now BaseObject#foo rather than BaseObject.foo.

     * @instance
     */
    foo: null
};

/** Generates BaseObject instances. */
function fooFactory(fooValue) {
	var props = { foo: fooValue };
	return Object.create(BaseObject, props);
}