如果注释是安全的,那么为什么不用`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?

查看:94
本文介绍了如果注释是安全的,那么为什么不用`x = 0; x + / * cmt * / +;`或`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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆