应该有一个多行var f = function(){/ * Code * /}得到一个分号 [英] should a multiline var f = function() { /* Code */ } get a semicolon

查看:207
本文介绍了应该有一个多行var f = function(){/ * Code * /}得到一个分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当设置一个变量以引用多行声明中的函数时,应该后跟一个分号。以下面的例子:

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 * /}得到一个分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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