如果注释是安全的,那么为什么不用`x = 0; x + / * cmt * / +;`或`var f / * cmt * / oo ='foo';`work? [英] If comments are safe, then why doesn't `x = 0; x+/*cmt*/+;` or `var f/*cmt*/oo = 'foo';` work?
问题描述
这个线程灵感问题。这里是代码示例。
This thread inspired the question. Here are the code samples again. I'm looking for an answer that tells exactly what is going on.
两个 x = 0; x + / * cmt * / +;
和 var f / * cmt * / oo ='foo';
产生语法错误,在此问题错了。
Both x = 0; x+/*cmt*/+;
and var f/*cmt*/oo = 'foo';
produce syntax errors, which renders the answers in this question wrong.
推荐答案
从 ECMAScript参考:
注释表现得像空格,并且被丢弃,除非,如果
MultiLineComment包含一个行终止符字符,
注释被认为是一个LineTerminator,用于通过语法语法解析
。
Comments behave like white space and are discarded except that, if a MultiLineComment contains a line terminator character, then the entire comment is considered to be a LineTerminator for purposes of parsing by the syntactic grammar.
这篇关于如果注释是安全的,那么为什么不用`x = 0; x + / * cmt * / +;`或`var f / * cmt * / oo ='foo';`work?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!