做什么(function($){...})(jQuery);做/意思是? [英] What does (function( $ ){...})( jQuery ); do/mean?

查看:85
本文介绍了做什么(function($){...})(jQuery);做/意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于jquery的可重用插件,我有点陌生.我已经多次浏览过此代码,无法确切知道发生了什么.

I am a bit new to reusable plugins for jquery. I have ran across this code several times and can't figure out exactly what is going on.

(function( $ ){
   ...
})( jQuery );

有人可以启发我吗?

推荐答案

它允许作者在插件中使用$函数,而无需将其暴露于全局范围内-只是使插件本身之外的内容更加简洁.

It allows the author to use the $ function within the plugin without exposing it to the global scope - just keeps things a bit cleaner outside of the plugin itself.

我认为这是开发jQuery插件的最佳做法-确保我在文档中的某处看到了它!

I believe this is best practice for developing jQuery plugins - sure I saw it mentioned in the docs somewhere!

这篇关于做什么(function($){...})(jQuery);做/意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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