How to document callbacks using JSDoc?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)