You mean something like the following?:
(function() {
// ...
})();
This basically ensures that any "var" declarations are kept private (they are scoped to the anonymous function in which they have been placed) rather than global. For example, consider:
var counter = 0;
window['inc'] = function() {
return counter++;
};
vs.
(function() {
var counter = 0;
window['inc'] = function() {
return counter++;
};
})();
Both of these have the effect of defining a function window.inc
that returns a counter that gets incremented; however, in the first version, counter
is actually visible to all other modules, because it is in the global scope, whereas the latter ensures that only window.inc
can access counter
.
Note that the code creates a function and immediately invokes it (that's what the last parens are for).