Possible Duplicate:
How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?
I am trying to learn about js scopes and anonymous functions. I have tried to read the jQuery.js file and it looks like this:
(function( window, undefined ) {
...
}(window));
Why does it have in the function params undefined when no parameter is being passed to it when it is executed?
This method is used so you can be sure that no one has previously redefined undefined value with something like
var undefined = true;
or with other tricky/evil assignments outside the jQuery scoped function. So, inside that function every comparison done against undefined is safe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With