I see no situation where I need this
(function(param){
alert(param);
//do something
})("derp");
istead of this
alert("derp");
//do something
EDIT: ok, thanks everybody, i think i got it.
so if you have this:
var param = "x";
var heya = "y";
(function(param){
alert(param);
//do something
})(heya);
the global variable “param” will be ignored in the scope of the anonymous function?
How about this scenario?
Example #1 – Uses an Immediately Invoked Function Expression that closes over a single variable and returns another function. Resulting in a beautiful, encapulated function.
VERSUS
Example #2 – Uses a Function Declaration w/ a global variable
It is a contrived example but still a real case scenario in situations where people may want to generate consecutive UNIQUE ID’s with no possibility of collision.