I've been looking at some sample projects in AngularJS and have come across several times with the following code:
(function () {
angular.module('meuModulo', [
'alguma.dependencia',
'outra.dependencia'
]);
})();
This same code, in the pattern I'm used to, would be:
angular.module('meuModulo', [
'alguma.dependencia',
'outra.dependencia'
]);
That is, the code was placed inside a function
.
Is there a difference between the first and second examples? If yes, what are the advantages of using the first approach instead of the second one?
The above code is just an example of a module creation in AngularJS.