How to document callbacks using JSDoc?

前端 未结 2 1306
南方客
南方客 2021-01-01 10:51

Given a Javascript function that takes callback functions as parameters:

var myFunction = function(onSuccess, onFailure) {...}

How do I doc

相关标签:
2条回答
  • 2021-01-01 11:04

    It seems this functionality does not exist yet.

    This functionality was added as of JSDoc 3.1. See:

    • http://code.google.com/p/jsdoc-toolkit/issues/detail?id=319
    • https://github.com/jsdoc3/jsdoc/issues/260

    for a related discussion.

    0 讨论(0)
  • 2021-01-01 11:09

    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.

    0 讨论(0)
提交回复
热议问题