0

I see many people using self invoking functions as a wrapper for angular modules e.g.

(function() {

  var app = angular.module('directivesModule');

  app.directive('domDirective', function () {
      return {
          restrict: 'A',
          link: function ($scope, element, attrs) {

          }
      };
  });

}());

Is there any advantage of wrapping like this? Or it is just a matter of coding style?

Thank you!

andrey
  • 1,867
  • 3
  • 21
  • 34
  • 4
    read this answer http://stackoverflow.com/a/8228308/2435473 would help you.. – Pankaj Parkar Sep 06 '15 at 13:34
  • It's an [iife](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression), but it also helps prevent against polluting the global scope unnecessarily. – Nick Salloum Sep 07 '15 at 00:23

0 Answers0