Does the syntax '///' have any special meaning?

15

I was using notepad ++ (v 6.5) to write a file in javascript when I noticed the following:

I wrote a comment line starting with /// , three instead of the usual two. In execution this line seems to be ignored, but it is not colored as a comment. (Note also that the bottom of the line is white, of a different color). Is this a bug in the syntax highlighter of notepad ++ or is it some special javascript syntax that I do not know? Something related to /regex/ ?

    
asked by anonymous 05.05.2014 / 16:55

2 answers

24

This set of three bars is commonly used by some programs for formatting code documentation (such as Doxygen ) as a way of indicating that the comment of a single line should be included in the generated documentation. In practice it is still a comment of a line, but it is a special comment.

Some editors, such as Visual Studio , for example, colorize these comments differently just to indicate that it is a documentation. Others, do not differentiate this from a normal comment (as in the case of StackOverflow itself - see below). The following function (extracted from the above link for Visual Studio) exemplifies the use of this type of comment:

<script type="text/javascript">
function areaFunction(radiusParam)
{
    /// <summary>Determines the area of a circle based on a 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 * radiusParam * radiusParam;
    return areaVal;
    // Note como o StackOverflow NÃO COLORE esse comentário DE FORMA DIFERENTE do anterior...
}
</script>

The Notepad ++ (syntax highlighter) colorizer (the reference version is 6.5.5) is able to differentiate these characters from a simple comment. In some languages where this usage is most common, there is a specific setting for this:

Iintentionallychangedthestyleofdocumentationcomments(COMMENTLINEDOC)inJava*toblue,asawayofillustrating.Thisisdonedirectlyinthe"Style Configurator" tool available in the Notepad ++ "Settings" menu:

*AlthoughNotepad++colorfullycommentscommentswiththreeslashes(toindicatedocumentation),therearenoreferencestothisstyleotherthan/**<codigo>*/intheJavadocdocumentation-asindicatedinthecommentmadeinthisresponse.

InthecaseofJavascript,Notepad++alsodifferentiatesthiscommentfrom"common", but does not provide a unique coloring option for it (as it does for Java). Honestly, I do not understand the reason for the lack of this color setting option, since the distinction is clearly made (if there is a bug it might be in this lack of configuration, not in the differentiation of the types of comments).

Just to be precise about what happens in the case of this comment with three bars in the case of Javascript , the line falls into the default setting ( default ) of global styles ( global styles ), and therefore has the blank background color distinct from the rest of the file. If it is in your interest, you can still set the color for Javascript by changing here:

    
05.05.2014 / 18:15
4

According to the Specification ECMA-262 , in the case of comments from single line , any type of character is accepted after the addition of the two "bars" that start the comment ( // ).

So, despite the color change in your editor, the JavaScript comment is still valid.

    
05.05.2014 / 17:17