javascript - Purpose to create anonymous function and call it immediately -


i following angularjs tutorial, , encountered this:

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

i wondering difference between , this:

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

as far understanding goes, both define new angularjs module, guessing there more it?

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 above snippet. global variable , copied 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 snippet, making not copy window(global) object , modularising code

hope helps


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -