[英]What kind of construct would use the comment delimiter */ in a Javascript?
From "Javascript: the Good Parts": the Good Parts : 从“Javascript:好零件”:好零件 :
Avoid
/* … */
for comments,*/
appears in useful constructs in javascript.避免
/* … */
用于评论,*/
出现在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 /.*/
?) 我很好奇这些“有用的结构”可能是什么,因为我想不出任何OTOH(除了像
/.*/
这样的正则表达式之外)
是的,正则表达式很可能是他所指的。
The blogger was trying to abbreviate what Crockford wrote at JavaScript: The Good Parts, Chapter number 2 ( Grammar ). 这位博主试图缩写Crockford在JavaScript中所写的内容:The Good Parts,Chapter 2(Grammar)。 This topic comes on the last paragraph of the first section ( Whitespace ).
本主题出现在第一部分(Whitespace)的最后一段。 It says,
它说,
The /* */ form of block comments came from a language called PL/I.
块注释的/ * * /形式来自一种叫做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.
PL / I选择那些奇怪的对作为评论的符号,因为它们不太可能出现在该语言的程序中,除了字符串文字。 In JavaScript, those pairs can also occur in regular expression literals, so block comments are not safe for commenting out blocks of code.
在JavaScript中,这些对也可以出现在正则表达式文字中,因此块注释对于注释掉代码块是不安全的。 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.
因此,建议避免使用/ * * / comments并使用//注释。 In this book, // will be used exclusively.
在本书中,//将被独占使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.