简体   繁体   中英

Make JSDoc comment for function which takes another function as parameter

Imagine a function which accepts an "onUpdate" function as a parameter:

 /**
 * @param {function} onUpdate
 * @returns {null}
 */
static async init(onUpdate) {
    ...
    onUpdate(true);
};

onUpdate takes a boolean as an argument. I want to add that arguments to @param {function} onUpdate .

Is there a way?

Some magnificent devs managed to do it on these addEventListener functions:

I think in screenshot you see typescript hint. But you can do something like this :

/**
 * This callback is displayed as a global member.
 * @callback someCallback
 * @param {number} param1
 * @param {number} param2
 * @returns {number}
 */

/**
 * 
 * @param {someCallback} cb 
 */

function someFunction(cb) {

}

And see this hint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM