共用方式為


JScript 註解

單行 JScript 註解是以一對正斜線 (//) 為首。

程式碼中的註解

下面是單行註解加上一行程式碼的範例。

// This is a single-line comment.
aGoodIdea = "Comment your code for clarity.";

多行 JScript 註解以一個正斜線和星號 (/*) 開始,並以相反的順序 (*/) 結束。

/*
This is a multiline comment that explains the preceding code statement.
The statement assigns a value to the aGoodIdea variable. The value, 
which is contained between the quote marks, is called a literal. A 
literal explicitly and directly contains information; it does not 
refer to the information indirectly. The quote marks are not part 
of the literal.
*/

如果您要在一個多行註解中嵌入另一個多行註解,JScript 會以非預期的方式來解譯最後產生的多行註解。 標記所嵌入之多行註解結尾的 */ 符號,會被解譯為整個多行註解的結尾。 如此一來,在所嵌入的多行註解後面的文字會被解譯為 JScript 程式碼,這就會產生語法錯誤。

在以下範例中,第三行文字被解譯為 JScript 程式碼,因為 JScript 已經將最內部的 */ 解譯為最外部註解的結束:

/* This is the outer-most comment
/* And this is the inner-most comment */
...Unfortunately, JScript will try to treat all of this as code. */

我們建議您將所有的註解寫成單行註解區塊, 這樣稍後您便能將含有多行註解的大量程式碼區段標記為註解。

// This is another multiline comment, written as a series of single-line comments.
// After the statement is executed, you can refer to the content of the aGoodIdea
// variable by using its name, as in the next statement, in which a string literal is
// appended to the aGoodIdea variable by concatenation to create a new variable.
var extendedIdea = aGoodIdea + " You never know when you'll have to figure out what it does.";

另一個方法是使用條件式編譯,有效地將大量程式碼區段標記為註解。

請參閱

其他資源

JScript 參考

JScript 語言教學課程

條件式編譯