语法
使用 JSDoc 标记词典(默认启用)
@interface [<name>]
使用 Closure Compiler 标记词典
@interface
概述
@interface
标记将一个符号标记为其他符号可以实现的接口。例如,代码可能定义一个父类,其方法和属性被存根。可以将 @interface
标记添加到父类,以指示子类必须实现父类的方法和属性。
将 @interface
标记添加到接口的顶级符号(例如,构造函数)。无需将 @interface
标记添加到接口的每个成员(例如,接口的实例方法)。
如果使用 JSDoc 标记词典(默认启用),还可以使用虚拟注释定义接口,而不是为接口编写代码。有关示例,请参阅“定义接口的虚拟注释”。
示例
在以下示例中,Color
函数表示其他类可以实现的接口
/**
* 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<number>} An array containing the red, green, and blue values,
* in that order.
*/
Color.prototype.rgb = function() {
throw new Error('not implemented');
};
/**
* 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<number>} An array containing the red, green, and blue values,
* in that order.
*/