What does the three slashes in javascript do?

2020-07-17 05:40发布

问题:

I'm still new to Javascript so when my editor highlights it I'm intrigued. what exactly does it do?

Example: /// things go after here

回答1:

Some documentation generators regard three slashes /// as introducing documentation comments to JavaScript.

See

http://msdn.microsoft.com/en-us/library/bb514138(v=vs.110).aspx

So three slashes work the same as two slashes as far as JavaScript is concerned (it's a comment-to-end-of-line), but three slashes can be interpreted by documentation generators to indicate a documentation section.

Example:

  function getArea(radius)
  {
      /// <summary>Determines the area of a circle that has the specified radius parameter.</summary>
      /// <param name="radius" type="Number">The radius of the circle.</param>
      /// <returns type="Number">The area.</returns>
      var areaVal;
      areaVal = Math.PI * radius * radius;
      return areaVal;
  }


回答2:

The first two slashes start a comment. The third slash does nothing.

The two main ways to comment in JS:

/* This way
Can go multi-line */

// This way is one line only


回答3:

I believe it is a way to define a "higher level" single line comment in some editors/documentation programs:

E.g. In macrabbit's espresso editor it highlights these single line comments in the navigation pane



回答4:

Three slashes in JavaScript (and some other languages such as C#) are used for documentation comments. These are used to generate XML documentation, and are done in a certain format before functions etc, to specify the description of the function and its parameters and parameter types.

http://msdn.microsoft.com/en-us/library/bb514138(v=vs.110).aspx