angularjs - when defining an angular module - should I wrap in self executing function? -
(function (angular) { "use strict"; angular.module('module') .filter('lefilter', function() { ... }); })(angular); saw code in new project i'm working on. begin module @ root of file , dont use 'strict' mode.
angular.module('module') .filter('lefilter', function() { ... }); i've never ran single issue doing this.
in context of angular application, there gain self-executing function , 'strict' mode?
i don't see major benefit running in iife(immediately-invoked function expression), how angular wrapping things in closures (such in filter). insulate naming collisions scope created using them, decrease readability. bit more useful in regard if stored angular modules in variables upon instantiation , used when adding controllers/filters/etc. rather using module getter, don't recommend doing that.
if using build system such gulp or grunt might worth having compile these files inside of iife, , leaving source without them.
i recommend using "use strict" because makes write cleaner code less chance of having casting issues. but, again, doesn't "gain" prevents bad possible occurring.
both of these safe-guards more-so giving sort of advantage.
Comments
Post a Comment