How does this JavaScript/JQuery Syntax: (function( window, undefined ) { })(window) work?
- by DKinzer
Have you ever taken a look under the hood at the JQuery 1.4 source code and noticed how it's encapsulated in the following way:
(function( window, undefined ) {
//All the JQuery code here
...
})(window);
I've read an article on JavaScript Namespacing and another one called "An Important Pair of Parans," so I know some about what's going on here.
But I've never seen this particular syntax before. What is that undefined doing there? And why does window need to be passed and then appear at the end again?