来自"Javascript: the Good Parts": the Good Parts:
避免使用
/* … */
进行注释,因为*/
在javascript中出现在有用的结构中。请使用//
。
我很好奇这些“有用的结构”是什么,因为我想不出任何反例(除了像/.*/
这样的正则表达式?)
来自"Javascript: the Good Parts": the Good Parts:
避免使用
/* … */
进行注释,因为*/
在javascript中出现在有用的结构中。请使用//
。
我很好奇这些“有用的结构”是什么,因为我想不出任何反例(除了像/.*/
这样的正则表达式?)
博主试图缩写Crockford在《JavaScript: The Good Parts》第2章(语法)中所写的内容。这个话题出现在第一节(空格)的最后一段。它说:
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.
/*…*/
进行注释。 - RobG