当设置一个变量以引用多行声明中的函数时,应该后跟一个分号。以下面的例子:
When setting a variable to reference a function in a multi-line declaration, should it be followed by a semicolon. Take the folling for example:
function sayHi(name) { (window.console && console.log || alert)('Hello ' + name); } var sayBye = function(name) { (window.console && console.log || alert)('Cya ' + name); };在第二个声明之后应该有一个分号,因为它符合var关键字,函数定义的末尾通常没有分号。
Should there be a semicolon after the second declaration as it fits with a var keyword, on the other hand, function definitions don't usually have a semicolon at the end.
推荐答案第一个函数是一个 / em>,而不是语句。 它不需要一个分号。
The first function is a function declaration, not a statement. It does not need a semicolon.
第二个函数是一个常规语句, 。 与所有其他语句一样,它应以可选的分号结尾。
The second function is a regular statement that happens to involve a function expression. Like all other statements, it should end with an optional semicolon.
更多推荐
应该有一个多行var f = function(){/ * Code * /}得到一个分号
发布评论