What does the three slashes in javascript do?

…衆ロ難τιáo~ 提交于 2019-12-21 19:53:11

问题


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



来源:https://stackoverflow.com/questions/10423469/what-does-the-three-slashes-in-javascript-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!