語法
@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
*/