Possible Duplicate:
Is there a difference between (function() {…}()); and (function() {…})();?
I've seen the following syntax used to prevent variables from getting into global scope:
(function ($, undefined)
{
})(jQuery);
More recently I've seen code doing it this way:
(function ($, undefined)
{
} (jQuery));
I find the 1st way makes the most sense to me. I mentally read it as:
I've defined a function and I wish to wrap it into an expression, (the first set of parenthesis). That expression is a function object which I then wish to call using method syntax and the parameter I'm passing to this function object is jQuery.
The 2nd syntax is less clear to me, because it looks like the outer parenthesis are unnecessary.
My javascript knowledge isn't quite good enough yet to feel comfortable w/ the 2nd syntax. Do these produce identical behavior? Is there any difference at all?
What would happen if you did this?
function ($, undefined)
{
} (jQuery);