应该有一个多行var f = function(){/ * Code * /}得到一个分号

编程入门 行业动态 更新时间:2024-10-25 00:35:01
本文介绍了应该有一个多行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 * /}得到一个分号

本文发布于:2023-11-16 06:26:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601806.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分号   有一个   function   var   Code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!