简体   繁体   中英

What kind of construct would use the comment delimiter */ in a Javascript?

From "Javascript: the Good Parts": the Good Parts :

Avoid /* … */ for comments, */ appears in useful constructs in javascript. Use // .

I'm curious as to what these "useful constructs" might be, as I can't think of any OTOH (except maybe a regex like /.*/ ?)

是的,正则表达式很可能是他所指的。

The blogger was trying to abbreviate what Crockford wrote at JavaScript: The Good Parts, Chapter number 2 ( Grammar ). This topic comes on the last paragraph of the first section ( Whitespace ). It says,

The /* */ form of block comments came from a language called PL/I. PL/I chose those strange pairs as the symbols for comments because they were unlikely to occur in that language's programs, except perhaps in string literals. In JavaScript, those pairs can also occur in regular expression literals, so block comments are not safe for commenting out blocks of code. For example:

  /* var rm_a = /a*/.match(s); */ 

causes a syntax error. So, it is recommended that /* */ comments be avoided and // comments be used instead. In this book, // will be used exclusively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM