構文
@callback <namepath>
概要
@callback タグは他の関数に渡されうるコールバック関数に関する情報を提供します。それにはコールバックのパラメータと戻り値が含まれます。@method に対して指定できるタグはすべて含ませることができます。
コールバックを定義したら、@typedef タグを使用して定義されたカスタム型と同じ方法で使用できます。具体的には、コールバックの名前を型名として使用できます。これにより、関数パラメータがある種のコールバック型を含まなければならないことを示せます。
ある特定のクラスの型定義と共にコールバックを表示させたい場合は、コールバックにそのクラスの内関数であることを示す namepath を与えることができます。また、複数のクラスから参照されるグローバルなコールバック型を定義することもできます。
例
/**
* @class
*/
function Requester() {}
/**
* Send a request.
* @param {Requester~requestCallback} cb - The callback that handles the response.
*/
Requester.prototype.send = function(cb) {
// code
};
/**
* This callback is displayed as part of the Requester class.
* @callback Requester~requestCallback
* @param {number} responseCode
* @param {string} responseMessage
*/
/**
* @class
*/
function Requester() {}
/**
* Send a request.
* @param {requestCallback} cb - The callback that handles the response.
*/
Requester.prototype.send = function(cb) {
// code
};
/**
* This callback is displayed as a global member.
* @callback requestCallback
* @param {number} responseCode
* @param {string} responseMessage
*/