jQuery stuff I haven't seen before; jQuery(this) and ;(function($) { ... })(jQuery)
I'm working with a jQuery plugin, and it has some unusual coding that I think might be kinda old school. For the sake of my own education, I'm hoping you guys and gals can give me some clarification.
First, I see this:
- var $elem = jQuery(this);
I've never seen
jQuery(this)... is it the same as
$(this)? I did some tests and they appear to be the same, but later in the script the author uses $(this)... so why did he use jQuery(this) in one part and $(this) later?
And is there a reason he used
$elem instead of just
elem?
Second, I see a function like this:
- ;(function($) {
- var foo = {
- bar : 'a',
- example : 'b'
- }
- function whatever(event) {
- ...
- }
- })(jQuery);
I've never seen
;(function($) { ... })(jQuery), what's the actual purpose of this? There are several other variables and functions in it, I just abbreviated it here for the post.