分号 [英] semicolon

查看:69
本文介绍了分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我查看javascript圣经时我没有找到任何例子

脚本,其中包含以分号结尾的行。然而,当我仔细阅读这个新闻组时,我发现有时会有结尾的分号和

有时候没有。


也许有人可以开导我在

javascript中的正确用法。


谢谢


f。

Hi,
When I look through the "javascript bible" I don''t find any example
scripts that have lines with ending semicolons. However when I peruse
this newsgroup I find that sometimes there are ending semicolons and
sometimes not.

Perhaps someone could enlighten me as to their proper usage in
javascript.

thank you

f.

推荐答案




fritz写道:



fritz wrote:

当我看通过javascript圣经我找不到任何带有以分号结尾的行的示例
脚本。然而,当我仔细阅读这个新闻组时,我发现有时会有结尾的分号,而有时则没有。

或许有人可以启发我在
javascript中的正确用法。
When I look through the "javascript bible" I don''t find any example
scripts that have lines with ending semicolons. However when I peruse
this newsgroup I find that sometimes there are ending semicolons and
sometimes not.

Perhaps someone could enlighten me as to their proper usage in
javascript.




在JavaScript中,分号终止一个语句,与

其他类C语言的语句非常相似。然而,像JavaScript这样的脚本语言之一是一个自动分号插入,可以免费使用
脚本编写器来解决这个问题。因此,在C或Java中你需要写b / b
声明1;

声明2;


你可以免费写一下


陈述1

陈述2


你应该小心关于返回或抛出的语句如

自动插入的分号会伤害你并改变你的脚本的含义,例如你的b $ b如果您编码

返回

表达式

然后由于自动分号插入的规则被解析为

返回;

表达式

然后返回语句不会返回评估表达式但结果未定义的结果。

标准化核心JavaScript语言的ECMAScript标准

为脚本编写者提供了以下实用建议规则,以避免使用自动插入的分号出现问题:




?后缀++或 - 运算符应与其操作数出现在同一行。

? return或throw语句中的表达式应该与返回或

抛出令牌相同的

行开始。

? break或continue语句中的标签应该与

中断或

继续令牌在同一行。

-


Martin Honnen
http://JavaScript.FAQTs。 com /


Martin Honnen写道:
Martin Honnen wrote:
在JavaScript中,分号终止一个语句,与
其他类C语言。然而,像JavaScript这样的脚本语言之一是一个自动分号插入,可以让脚本人免于明确地编写它。因此,在C或Java中你必须用JavaScript编写声明1;
声明2;

你可以自由写作
<声明1
声明2

然而你应该注意像return或throw这样的语句
一个自动插入的分号会伤害你并改变你的意思
脚本例如如果你编码
返回表达
然后由于自动分号插入的规则被解析为
返回;
表达
和return语句然后不会返回评估表达式的结果,但返回值未定义。

标准化核心JavaScript语言的ECMAScript标准为脚本编写者提供了以下规则以避免
自动插入分号的问题:

?后缀++或 - 运算符应与其
操作数出现在同一行。
? return或throw语句中的表达式应该与返回或
throw标记在同一行上开始。
?中断或继续声明中的标签应与中断或
继续令牌在同一行。
In JavaScript a semicolon terminates a statement, much the same as in
other C-like languages. However one of the scripting language like
features of JavaScript is an automatic semicolon insertion to free
scripters from having to write it explictly. Thus while in C or Java you
have to write

statement1;
statement2;

in JavaScript you are free to write

statement1
statement2

You should however be careful about statements like return or throw as
an automaticaly inserted semicolon can hurt you and change the meaning
of your script e.g. if you code
return
expression
then due to the rules of automatic semicolon insertion that is parsed as
return;
expression
and the return statement then does not return the result of evaluating
the expression but the value undefined.
The ECMAScript standard which standardizes the core JavaScript language
gives the following rules of practical advice to scripters to avoid
problems with automatically inserted semicolons:

? A postfix ++ or -- operator should appear on the same line as its
operand.
? An Expression in a return or throw statement should start on the same
line as the return or
throw token.
? A label in a break or continue statement should be on the same line as
the break or
continue token.



非常感谢Martin !我刚刚下载了ECMAScript262和

就可以了。然后我认为终止每一行最多是作者和b $ b作者并且从长远来看它没有任何区别,除了

之类的东西,比如''return''或者break 。因此,如果语言看到结尾'';''它

不会添加另一个。


顺便说一句,我用'javascript IDE'搜索'并且提出的不是太多

但是在2000年有一些参考文献。有没有人试图将javascript

改为perl等通用语言?


f。


Thank you very much Martin! I just downloaded the ECMAScript262 and
will have a go at it. I take it then that terminating each line is up to
the writer and doing it makes no difference in the long run except for
things like ''return'' or break. So if the language sees an ending '';'' it
doesn''t add another.

BTW, I googled on ''javascript IDE'' and came up with not too much
but a few references back in 2000. Has anyone tried to take javascript
up to a general purpose language such as perl?

f.





fritz写道:


fritz wrote:
有没有人试图将javascript升级为
一种通用语言,如perl?
Has anyone tried to take javascript up to
a general purpose language such as perl?




J(ava)脚本正在其他地方使用作为浏览器的环境,

Windows可以将它用于Windows脚本宿主的自动化和ASP页面中的

服务器端脚本。

使用JavaScript的另一个自动化示例是< http://www.jsdb.org/>。


虽然这些用法不能使JavaScript成为通用编程

语言肯定表明了语言正在

浏览器之外使用。


-


Martin Honnen
< a rel =nofollowhref =http://JavaScript.FAQTs.com/target =_ blank> http://JavaScript.FAQTs.com/


这篇关于分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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