I’ve seen this pattern a lot in javascript files:
(function ($)
{
//Perform operation X
}(jQuery));
Is there a difference between placing the above code in a js file vs the following:
function myFunc($)
{
//Perform operation X
}
myFunc(jQuery);
Or is it simply more terse?
Your second snippet defines a public symbol,
myFunc. If anyone else is using that symbol for a library, you would overwrite it and could destroy its functionality. The first snippet doesn’t have a name, and is therefore safer.