jQuery: What does (function($) {})(jQuery); mean?
- by Legend
I am just starting out with writing jQuery plugins. I wrote three small plugins but I have been simply copying the line into all my plugins without actually knowing what it means. Can someone tell me a little more about these?
What does this do? (I know it extends jQuery somehow but is there anything else interesting to know about this)
(function($) {
})(jQuery);
What is the difference between the following two ways of writing a plugin:
Type 1:
(function($) {
$.fn.jPluginName = {
},
$.fn.jPluginName.defaults = {
}
})(jQuery);
Type 2:
(function($) {
$.jPluginName = {
}
})(jQuery);
I could be way off here and maybe both mean the same thing. In some cases, this doesn't seem to be working in a plugin that I was writing using Type 1. Any idea why? But in either case, I would appreciate any explanation.