jQuery $ 换行函数

发布于 2024-12-09 08:28:05 字数 230 浏览 1 评论 0原文

其中哪一个是正确的 - 因为我使用过的许多插件都向我展示了差异,我想知道为什么?

(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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偷得浮生 2024-12-16 08:28:05

他们都是一样的。

最初的 ; 使其即使在脚本组合器有问题且不在脚本之间添加 ; 的情况下也能正常工作。

They're all the same.

The initial ; makes it work even with buggy script combiners that don't add ;s between scripts.

雄赳赳气昂昂 2024-12-16 08:28:05

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文