What is the purpose of wrapping whole Javascript files in anonymous functions like “(function(){ … })()”?
It’s usually to namespace (see later) and control the visibility of member functions and/or variables. Think of it like an object definition. The technical name for it is an Immediately Invoked Function Expression (IIFE). jQuery plugins are usually written like this. In Javascript, you can nest functions. So, the following is legal: function outerFunction() { … Read more