0

New to JS. Using jonhpapa's Angular style guide and I noticed that when he suggests using the IIFE closure he always adds an extra set of empty parenthesis. Why?

(function() {
'use strict';

angular
    .module('app')
    .factory('logger', logger);

function logger() { }
})();
Robert Tan
  • 634
  • 1
  • 8
  • 21

1 Answers1

1

To elaborate on my comment - this is an example of a named function:

function x() { console.log('x'); }

In order to invoke the function, you need to add parenthesis after it's name like this:

x();

You do the same thing to unnamed functions in order to invoke them:

(function() { console.log('x'); })();
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100