很多次我看到在函数声明之后使用分号,或者在模块模式脚本的匿名“return”函数之后使用。什么时候在花括号后使用分号比较合适? 最佳答案 在语句后使用分号。这是一个声明:varfoo=function(){alert("bar");};因为它是一个变量赋值(即创建一个匿名函数并将其赋值给一个变量)。首先想到的不是语句的两件事是函数声明:functionfoo(){alert("bar");}和block:{alert("foo");}注意:相同的不带分号的block构造也适用于for、do和while循环.
代码如下:hellodocument.getElementById("test").addEventListener("click",function(){test()},false)functiontest(){varpostTypes=newArray('hello','there')(function(){alert('hellothere')})()}这会抛出一个:"UncaughtTypeError:objectisnotafunction"如果我将匿名函数调用/调用包装在另一组括号中,它将执行警报,但仍然会给我一个错误。如果我在“varpostTypes”定义之后加一个分号
代码如下:hellodocument.getElementById("test").addEventListener("click",function(){test()},false)functiontest(){varpostTypes=newArray('hello','there')(function(){alert('hellothere')})()}这会抛出一个:"UncaughtTypeError:objectisnotafunction"如果我将匿名函数调用/调用包装在另一组括号中,它将执行警报,但仍然会给我一个错误。如果我在“varpostTypes”定义之后加一个分号
这个问题在这里已经有了答案:WhatdoestheleadingsemicoloninJavaScriptlibrariesdo?(6个答案)关闭7年前。在JavaScript中的自调用函数前使用分号有什么好处?我在几个流行的jQuery插件中看到了这种方法,我很想知道这是否是JavaScript中我不知道的下一个很棒的东西。
这个问题在这里已经有了答案:WhatdoestheleadingsemicoloninJavaScriptlibrariesdo?(6个答案)关闭7年前。在JavaScript中的自调用函数前使用分号有什么好处?我在几个流行的jQuery插件中看到了这种方法,我很想知道这是否是JavaScript中我不知道的下一个很棒的东西。
这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:WhatdoestheleadingsemicoloninJavaScriptlibrariesdo?我注意到很多jQuery插件都以开头;(function(){/*somethinginhere*/})();我只是想知道开头的分号和结尾的空括号是干什么用的。
这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:WhatdoestheleadingsemicoloninJavaScriptlibrariesdo?我注意到很多jQuery插件都以开头;(function(){/*somethinginhere*/})();我只是想知道开头的分号和结尾的空括号是干什么用的。
我有兴趣在我的flex文件中添加GoogleGo中的分号插入。来自Go文档:SemicolonsLikeC,Go'sformalgrammarusessemicolonstoterminatestatements;unlikeC,thosesemicolonsdonotappearinthesource.Insteadthelexerusesasimpleruletoinsertsemicolonsautomaticallyasitscans,sotheinputtextismostlyfreeofthem.Theruleisthis.Ifthelasttokenbeforeanewl
我有兴趣在我的flex文件中添加GoogleGo中的分号插入。来自Go文档:SemicolonsLikeC,Go'sformalgrammarusessemicolonstoterminatestatements;unlikeC,thosesemicolonsdonotappearinthesource.Insteadthelexerusesasimpleruletoinsertsemicolonsautomaticallyasitscans,sotheinputtextismostlyfreeofthem.Theruleisthis.Ifthelasttokenbeforeanewl
我正在尝试将linux内核的kconfig实用程序移植到我的产品中编译时出现下一个错误:make[6]:***Noruletomaketarget`zconf.tab.c',neededby`zconf.tab.o'.Stop.我在Makefile.lib中找到了这个文件的下一条规则$(obj)/%:$(src)/%_shipped$(callcmd,shipped)它对我来说看起来不错,它只适用于内核,但不适用于我的产品。然后我在前一个规则之后添加了另一个规则。$(obj)/%c:$(src)/%c_shipped$(callcmd,shipped)现在它工作得很好。谁能给我解释一下