Possible Duplicate:
why do we need to pass in window and undefined into this jquery plugin?
I’ve seen jQuery source code does this:
(function(window, undefined){
...
}(window))
I get why is it useful to include undefined, if someone where to change “undefined” before. But window cant be changed. For all I know, it doesnt even need to be used, right? How could this be useful?
Micro optimisation.
Having
windowas a local variable is marginally faster than a global variable.It also minifies better. We can now minify the function parameter to
wand usew.setTimeoutetc instead ofwindow.setTimeout.Fewer bytes = better