理解$与iife中的jQuery而不是$ [英] understanding $ vs. jQuery in iife instead of $

查看:93
本文介绍了理解$与iife中的jQuery而不是$的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解两者之间是否有任何区别

I am trying to understand if there is any difference between:

(function($){

...

})(jQuery);

vs.

(function($){

...

})($);

请注意,jQuery已用$代替.这个可以吗?是否因为无法使用而在任何地方都不使用?它可以工作,但也许是非标准的?如果错误或可以,有人可以解释一下吗? 谢谢

Note the jQuery was replaced with a $. Is this ok? Is it not used anywhere because it can't work? It works but maybe it is non-standard? Can someone please explain this if it is an error or if it is ok? Thanks

推荐答案

其他JavaScript框架也可以使用$作为快捷方式.为了保证$是函数中的jQuery,请传递jQuery而不是$.定义函数或代码区域"的这种类型是为了确保在混合框架时$确实是jQuery.

Other JavaScript frameworks may also use $ as a shortcut. To guarantee that $ is jQuery inside your function, pass jQuery and not $ at the end. This type of defining a function or "code area" is to take sure that $ really is jQuery when mixing frameworks.

这篇关于理解$与iife中的jQuery而不是$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆