本文介绍了什么时候应该在花括号后使用分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我多次看到在函数声明之后或在模块模式脚本的匿名返回"函数之后使用分号.花括号后面什么时候用分号比较合适?
Many times I've seen a semicolon used after a function declaration, or after the anonymous "return" function of a Module Pattern script. When is it appropriate to use a semicolon after curly braces?
推荐答案
在语句后使用分号.这是一个声明:
You use a semicolon after a statement. This is a statement:
var foo = function() {
alert("bar");
};
因为它是一个变量赋值(即创建一个匿名函数并将其赋值给一个变量).
because it is a variable assignment (i.e. creating and assigning an anonymous function to a variable).
想到的不是语句的两件事是函数声明:
The two things that spring to mind that aren't statements are function declarations:
function foo() {
alert("bar");
}
和块:
{
alert("foo");
}
注意:没有分号的相同块结构也适用于 for
、do
和 while
循环.
Note: that same block construct without semi-colon also applies to for
, do
and while
loops.
这篇关于什么时候应该在花括号后使用分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!