Given a Javascript function that takes callback functions as parameters:
var myFunction = function(onSuccess, onFailure) {...}
How do I document onSuccess
's return type and arguments?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
A callback is a function passed as an argument to another function. This technique allows a function to call another function. A callback function can run after another function has finished.
A custom callback function can be created by using the callback keyword as the last parameter. It can then be invoked by calling the callback() function at the end of the function. The typeof operator is optionally used to check if the argument passed is actually a function. console.
js applications. A fallback function specifies an action that is performed whenever a call to a remote service fails. For example, you can use a fallback function to send a customized message about service failures to the client.
In JSDoc 3.1 and later, you can use the new @callback
tag to describe the callback function in a separate comment block. You can then refer to the callback in the docs for your method.
Here's an example:
/** @class */ function MyClass() {} /** * Do something. * @param {MyClass~onSuccess} cb - Called on success. */ MyClass.prototype.myFunction = function(cb) { // code }; /** * Callback used by myFunction. * @callback MyClass~onSuccess * @param {number} resultCode * @param {string} resultMessage */
See Use JSDoc for more information.
It seems this functionality does not exist yet.
This functionality was added as of JSDoc 3.1. See:
for a related discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With