What's the proper way to document callbacks with jsdoc?

后端 未结 4 944
春和景丽
春和景丽 2021-01-30 04:52

I\'ve spent quite a while scouring the internet looking for the best way to properly document callbacks with jsdoc, but unfortunately, I haven\'t found a great one yet.

4条回答
  •  天命终不由人
    2021-01-30 05:47

    Workaround to make VSCode understand it

    /**
     * @typedef {function(FpsInfo)} fpsCallback
     * @callback fpsCallback
     * @param {FpsInfo} fps Fps info object
     */
    
     /**
     * @typedef {Object} FpsInfo
     * @property {number} fps The calculated frames per second
     * @property {number} jitter The absolute difference since the last calculated fps
     * @property {number} elapsed Milliseconds ellapsed since the last computation
     * @property {number} frames Number of frames since the last computation
     * @property {number} trigger Next computation will happen at this amount of frames
     */
    
    /**
     * FPS Meter - Returns a function that is used to compute the framerate without the overhead of updating the DOM every frame.
     * @param {fpsCallback} callback Callback fired every time the FPS is computed
     * @param {number} [refreshRate=1] Refresh rate which the fps is computed and the callback is fired (0 to compute every frame, not recommended)
     * @returns {function} Returns a function that should be called on every the loop tick
     * @author Victor B - www.vitim.us - github.com/victornpb/fpsMeter
     */
    function createFpsMeter(callback, refreshRate = 1) {
        // ...
    }
    

提交回复
热议问题