javascript - Purpose to create anonymous function and call it immediately -
this question has answer here:
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
Post a Comment