構文
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');
};
次の例では、コードではなく、仮想コメントを使用して Color
インターフェイスを定義しています。
/**
* 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.
*/