Possible Duplicate:
What does the leading semicolon in JavaScript libraries do?
I have noticed a lot of jQuery plugins start with
;(function(){ /* something in here */ })();
我只是想知道开头的分号是干什么的,以及结尾的空括号.
Possible Duplicate:
What does the leading semicolon in JavaScript libraries do?
I have noticed a lot of jQuery plugins start with
;(function(){ /* something in here */ })();
我只是想知道开头的分号是干什么的,以及结尾的空括号.
分号就在那里,以防你在某个"坏"脚本没有正确地用分号结束最后一行之后包含这个脚本.在这种情况下,这两个脚本可能会合并,并导致无效代码.例如,如果要将多个脚本合并到一个响应中.
The () at the end is executing the function. This is creating a closure. Private variables and methods can be declared within the scope of this function that cannot be accessed from outside the script.