jQuery $ 换行函数
其中哪一个是正确的 - 因为我使用过的许多插件都向我展示了差异,我想知道为什么?
(function ($) {
//Code
})(jQuery);
(function ($) {
//Code
}(jQuery));
;(function($) {
//Code
}(jQuery));
我假设是第一个,但想知道为什么我看到了第二次和第三次迭代?
Which of these is correct - as a number of plugins I've used are showing me differences and I was wondering why?
(function ($) {
//Code
})(jQuery);
(function ($) {
//Code
}(jQuery));
;(function($) {
//Code
}(jQuery));
I am assuming the first however wondering why I've seen the 2nd and 3rd iterations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们都是一样的。
最初的
;
使其即使在脚本组合器有问题且不在脚本之间添加;
的情况下也能正常工作。They're all the same.
The initial
;
makes it work even with buggy script combiners that don't add;
s between scripts.FWIW,我在编写 jQuery 插件时总是使用第一个。
第二个看起来也可以工作,第三个看起来像第二个,同时还确保前一行以分号终止......可能有助于解决缩小问题。
FWIW, Ive always used the first when authoring jQuery plugins.
The second looks like it would also work, the third looks like the second while also ensuring that the previous line terminates in a semicolon... probably to aid in minification issues.