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这个词


基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01