18

In JavaScript comments, I want to mention a method present in some file. How can I link to that method in comment? Eg.

Say my method is:

function xyz() {
}

and say I am writing a comment like

// See also {method-link to xyz}

What should {method-link} be?

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Chacha
  • 411
  • 1
  • 5
  • 12

1 Answers1

22

To link to "something else" in JSDoc, including another method, use the {@link ...} tag. In your case, you would use:

// See also {@link xyz}

You'll then be able to Ctrl+click on xyz in WebStorm.

The JSDoc terminology for that "something else" is "namepath". Below follows the original answer by Andrew, which explains namepaths.


JSDoc3 styles:

Basic Syntax Examples of Namepaths in JSDoc 3

myFunction
MyConstructor
MyConstructor#instanceMember
MyConstructor.staticMember
MyConstructor~innerMember // note that JSDoc 2 uses a dash

Special cases: modules, externals and events.

/** 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
 */

For easy coding, I sometime use markdown style in comment:

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

// see the method [named of the method](file-name #method name)
xmedeko
  • 7,336
  • 6
  • 55
  • 85
Andrew_1510
  • 12,258
  • 9
  • 51
  • 52
  • So, for my example, putting xyz as it is should be fine. But why it does not become link like on pressing command. I am trying on webstorm. – Chacha Nov 03 '17 at 05:19
  • @Chacha: I've added at the top of the answer how to actually link to methods. – Dan Dascalescu Mar 18 '19 at 06:31