For the function (function($){})(), I#39;ve seen it with the word jQuery in it, why is that?(对于函数(function($){})(),我看到里面有jQuery这个词,这是为什么呢?)
问题描述
对于函数(function($){})(),我看到里面有jQuery这个词,这是为什么呢?
For the function (function($){})(), I've seen it with the word jQuery in it, why is that?
我已阅读此页面 Javascript:为什么 jQuery 会这样做:(function(){ ...});,它是如何工作的? 但它没有说明这样的示例:
I have read this page Javascript: why does jQuery do this: (function(){ ...});, and how does it work? but it didnt tell about an example like this:
(function($){})(jQuery);
括号中的那个jquery是做什么的?如果括号本身已经调用了函数,那我们为什么需要那个 jQuery 呢?
What does that jquery in the parenthesis do? If the parenthesis by itself already self calls the function then why do we need that jQuery in there?
推荐答案
是一个简单的函数调用,jQuery对象作为参数发送给匿名函数,例如:
Is a simple function invocation, the jQuery object is sent as an argument to the anonymous function, e.g.:
(function (foo) {
alert(foo); // alerts "hello"
})("hello");
这是定义插件的常用模式,基本上允许您在匿名函数范围内将jQuery对象引用为$
,即使jQuery运行在noConflict
模式.
It's a common pattern to define plugins, basically permits you to reference the jQuery object as $
in the scope of the anonymous function, even if jQuery is running in noConflict
mode.
这篇关于对于函数(function($){})(),我看到里面有jQuery这个词,这是为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:对于函数(function($){})(),我看到里面有jQuery这个词


- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01