语法
🌐 Syntax
@callback <namepath>
概述
🌐 Overview
@callback 标签提供有关可以传递给其他函数的回调函数的信息,包括回调函数的参数和返回值。你可以包含任何可以为 @method 提供的标签。
🌐 The @callback tag provides information about a callback function that can be passed to other functions, including the callback's parameters and return value. You can include any of the tags that you can provide for a @method.
一旦你定义了一个回调,你可以像使用用 @typedef 标签定义的自定义类型一样使用它。特别是,你可以使用回调的名称作为类型名。这允许你指明一个函数参数应该包含某种类型的回调。
🌐 Once you define a callback, you can use it in the same way as a custom type defined with the @typedef tag. In particular, you can use the callback's name as a type name. This allows you to indicate that a function parameter should contain a certain type of callback.
如果你希望回调在特定类的类型定义中显示,你可以给回调一个名称路径,表明它是该类的内部函数。你也可以定义一个全局回调类型,以便从多个类中引用。
🌐 If you want a callback to be displayed with the type definitions for a specific class, you can give the callback a namepath indicating that it is an inner function of that class. You can also define a global callback type that is referenced from multiple classes.
示例
🌐 Examples
/**
* @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
*/