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 将覆盖文档元素的默认作用域(除非它处于全局作用域,在这种情况下它将保持全局)。

🌐 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);
}