Are There Any Benefits To Wrapping Angular Javascript File With The "(function() { ....[js Code Here]...... })();"
Solution 1:
So, what you're looking at there is an imediately invoked anonymous function.
Basically, this "pattern" is used, because if you're not using it, you're working in the global namespace javascript out-of-the-box runs in, which could lead to unwanted problems including third party libraries/plugins or other modules you wrote. More insight here, there or here
Solution 2:
The anonymous IIFE surrounding it causes variables to be in a new scope, instead of the default scope, which in a browser is global. See: What is the (function() { } )() construct in JavaScript? for more info.
The 'use strict';
activates strict mode inside the IIFE, which means that some edge cases in JavaScript will behave differently (EG. throwing an error instead of strange behaviour). For more info about strict mode, take a look at the MDN article.
Post a Comment for "Are There Any Benefits To Wrapping Angular Javascript File With The "(function() { ....[js Code Here]...... })();""