【问题标题】:How can I add a description to a function in javascript?如何在 javascript 中为函数添加描述?
【发布时间】:2022-08-03 17:28:26
【问题描述】:

我想向 js 函数添加描述,就像我在 C、C++、Python 中所做的那样......

我通过在函数定义的顶部添加注释来做到这一点,在提到的语言中,但是如果我使用 JavaScript(纯,NodeJS,ReactJS)它不会显示它。 乙:

结果(当我将光标放在函数或定义的调用中时):

但是我这种行为不会与 Js/NodeJs/React 一起复制。 以防万一我使用 Visual Studio Code。

标签: javascript node.js reactjs


【解决方案1】:

VSCode 和大多数 IDE 一样,会自动处理JSDoc cmets。例如:

/**
 * Does something nifty.
 *
 * @param   whatsit  The whatsit to use (or whatever).
 * @returns A useful value.
 */
function nifty(whatsit) {
    return /*...*/;
}

如果你想要类型提示,你可以用类型来增加它:

/**
 * Does something nifty.
 *
 * @param   {number} whatsit  The whatsit to use (or whatever).
 * @returns {string} A useful value.
 */
function nifty(whatsit) {
    return /*...*/;
}

【讨论】:

    猜你喜欢
    • 2011-08-08
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 2020-05-26
    • 1970-01-01
    相关资源
    最近更新 更多