0

I was following an angularjs tutorial, and I encountered something like this:

(function(){
    'use strict'
    angular.module('users',['ngMaterial]);
})();

I was wondering what is the difference between that and this:

angular.module('users',['ngMaterial']);

As far as my understanding goes, both define a new angularjs module, but I am guessing there is more to it?

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
yasar
  • 13,158
  • 28
  • 95
  • 160
  • 1
    http://stackoverflow.com/questions/2421911/what-is-the-purpose-of-wrapping-whole-javascript-files-in-anonymous-functions-li + if it's a tutorial they're probably adding more stuff later. – JJJ Nov 05 '16 at 21:30

1 Answers1

0

var module1=angular.module('users',['ngMaterial']);
console.log(window.module1);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

With the above snippet. It is a global variable and will be copied into global object(window)

(function(){
    'use strict'
    var  module1=angular.module('users',['ngMaterial']);
  console.log(module1);
})();
                                        
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

with this snippet, your making it to not copy into window(global) object and modularising the code

Hope it helps

Geeky
  • 7,420
  • 2
  • 24
  • 50