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
  • 594
  • 1
  • 8
  • 20

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
  • 46,658
  • 11
  • 63
  • 84