繁体   English   中英

如何向 javascript 中的 function 添加描述?

[英]How can I add a description to a function in javascript?

我想向 js function 添加描述,就像我在 C、C++、ZA327415F354127B56B...

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

在 C++ 中添加描述

结果(当我将 cursor 放入 function 或定义的调用中时): 显示的描述

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

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

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

这是在 VSCode 中使用 function 的截图:

VSCode IDE 显示了上面正在使用的漂亮功能,并显示了一个包含文档注释的文档框

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

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

如果您使用 TypeScript,则类型将是代码的一部分,而不是 JSDoc 中:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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