JS Doc评论链接方法

Cha*_*cha 4 javascript jsdoc

在 JavaScript 注释中,我想提及某个文件中存在的方法。如何在评论中链接到该方法?例如。

说我的方法是:

function xyz() {
}
Run Code Online (Sandbox Code Playgroud)

并说我正在写评论

// See also {method-link to xyz}
Run Code Online (Sandbox Code Playgroud)

{method-link} 应该是什么?

And*_*510 7

要链接到 JSDoc 中的“其他内容”,包括另一种方法,请使用{@link ...}标记。在您的情况下,您将使用:

// See also {@link xyz}
Run Code Online (Sandbox Code Playgroud)

然后,您将能够xyz在 WebStorm 中按住 Ctrl 键并单击。

“其他东西”的 JSDoc 术语是“名称路径”。下面是 Andrew 的原始答案,它解释了名称路径。


JSDoc3样式:

JSDoc 3 中名称路径的基本语法示例

myFunction
MyConstructor
MyConstructor#instanceMember
MyConstructor.staticMember
MyConstructor~innerMember // note that JSDoc 2 uses a dash
Run Code Online (Sandbox Code Playgroud)

特殊情况:模块、外部和事件。

/** A module. Its name is module:foo/bar.
 * @module foo/bar
 */

/** The built in string object. Its name is       external:String.
 * @external String
 */

 /** An event. Its name is module:foo/bar.event:MyEvent.
 * @event module:foo/bar.event:MyEvent
 */
Run Code Online (Sandbox Code Playgroud)

为了便于编码,我有时markdown在评论中使用样式:

// see function name in file dir/file.name

// see the method [named of the method](file-name #method name)
Run Code Online (Sandbox Code Playgroud)