I saw the following way of writing self-starting functions:
(function (app) { app.foo = { bar: function(){} }; }(App));
Where App is a global object.
I wonder why we need to pass the App as a parameter to a function? Why not just use this:
(function () { App.foo = { bar: function(){} }; }());
I see only one advantage of using the first method. If for some reason we rename the App object, then we can easily rename the parameter in brackets, and our code will work the way it works. But in the case of the second method, we probably need to rename the App to all the places where we use it.
Are there any other differences?
source share