A lot of reasons...
keep your code clean, modulable, flexible, extensible etc... juste by adding or removing some part codes.
You can check librairies like Mootools ( core-builder ), jQuery ore others that provides sort of "bundles".
Those bundles very frequently can be used "as-is", without the others bundles ( except the very core one ). But they also provide functions and methods that can be used when they are loaded. Like here, this code the createAboutView to the application.
So you have (function() { //core code })(); (function() { //module one code with his own work/process functions })(); (function() { // module two with his own work/process function })();
Module one is independant of the module two. All he need is on the core ( and sometimes the required modules ) and in his own scope.
--- update
Module two needs some functions to work. But those functions are not needed by the core or the module one, just in the second module scope.
One another big reason is when you're declaring some function that depends on the current process. This topic show why you sometimes have to define functions ( and it can be recursive, function into function into function to keep scope and states ).
little exemple :
var a = [], j, k;
(function() {
var i;
for(i = 5; i--;)
a[i] = function() { alert(i); };
})();
for(k = 0, j = a.length; k < j; k++)
a[k]();
In this case, i is always -1, because when i call the function, i refer to the i on the self-executed function, which is now at '-1' because of the loop.
In those example below
var a = [], j, k;
(function() {
var i;
for(i = 5; i--;)
(function(i) { a[i] = function() { alert(i); }; })(i);
})();
for(k = 0, j = a.length; k < j; k++)
a[k]();
OR
var a = [], j, k;
(function() {
var i;
var alerti = function(i) {
return function() { alert(i); };
};
for(i = 5; i--;)
a[i] = alerti(i);
})();
for(k = 0, j = a.length; k < j; k++)
a[k]();
creating a function ( or an other self-executing function ) into a self-executing function allow me to keep a scope