(function() {
this.Lib = {};
}).call(this);
Defines the Lib
property of the Object it's called on, and is immediately called on this
which is typically the window
. It may instead refer to the Object that owns the method in which it is called.
(function() {
var Lib = {}; window.Lib = Lib;
})();
Defines the Lib
property of window
regardless of where it's called (although it's also called immediately).
(function(global) {
var Lib = {}; global.Lib = Lib;
})(global);
Defines the Lib
property of the object passed to the function. It's called immediately, but will result in an error unless you've defined a value for global
in the current scope. You might pass window
or some namespacing Object to it.
These aren't actually different ways of defining "anonymous functions", they all use the standard way of doing this. These are different methods of assigning values to global (or effectively global) properties. In this sense, they are basically equivalent.
Of more significance would be, for instance, how they define methods and properties of the objects they return/construct/expose (that is, how they build Lib
itself).
All of these functions return undefined
and only the first could be usefully applied as a constructor (with the use of new
), so it would seem they are nothing more than initializers for the frameworks.