JSDoc 中文网

语法

¥Syntax

使用 JSDoc 标签字典(默认启用):

¥With the JSDoc tag dictionary (enabled by default):

@interface [<name>]

使用 闭包编译器 标签字典:

¥With the Closure Compiler tag dictionary:

@interface

概述

¥Overview

@interface 标签将一个符号标记为其他符号可以实现的接口。例如,你的代码可能定义一个父类,其方法和属性已被删除。你可以在父类中添加 @interface 标签,以指示子类必须实现父类的方法和属性。

¥The @interface tag marks a symbol as an interface that other symbols can implement. For example, your code might define a parent class whose methods and properties are stubbed out. You can add the @interface tag to the parent class to indicate that child classes must implement the parent class' methods and properties.

@interface 标记添加到接口的顶层符号(例如,构造函数)。你不需要将 @interface 标记添加到接口的每个成员(例如接口的实例方法)。

¥Add the @interface tag to the top-level symbol for the interface (for example, a constructor function). You do not need to add the @interface tag to each member of the interface (for example, the interface's instance methods).

如果你使用 JSDoc 标签字典(默认启用),你还可以使用虚拟注释定义接口,而不是通过为接口编写代码。请参阅“定义接口的虚拟注释”的示例。

¥If you are using the JSDoc tag dictionary (enabled by default), you can also define an interface with virtual comments, rather than by writing code for the interface. See "Virtual comments that define an interface" for an example.

示例

¥Examples

在下面的示例中,Color 函数表示其他类可以实现的接口:

¥In the following example, the Color function represents an interface that other classes can implement:

使用@interface 标签
/**

 * Interface for classes that represent a color.

 *  * @interface
 */
function Color() {}

/**

 * Get the color as an array of red, green, and blue values, represented as

 * decimal numbers between 0 and 1.

 *  * @returns {Array&lt;number>} An array containing the red, green, and blue values,

 * in that order.
 */
Color.prototype.rgb = function() {
    throw new Error('not implemented');
};

以下示例使用虚拟注释而不是代码来定义 Color 接口:

¥ The following example uses virtual comments, rather than code, to define the Color interface:

定义接口的虚拟注释
/**

 * Interface for classes that represent a color.

 *  * @interface Color
 */

/**

 * Get the color as an array of red, green, and blue values, represented as

 * decimal numbers between 0 and 1.

 *  * @function

 * @name Color#rgb

 * @returns {Array&lt;number>} An array containing the red, green, and blue values,

 * in that order.
 */