As I delve into the realm of HotTowel templates for AngularJS, a myriad of "why" questions flood my mind. While I have managed to answer some of them, one still remains elusive. Specifically, I am puzzled by the use of "Immediately-Invoked Function Expression (IIFE)" for controllers in the code snippet from "shell.js."
(function () {
'use strict';
var controllerId = 'shell';
angular.module('app').controller(controllerId,
['$rootScope', 'common', 'config', shell]);
function shell($rootScope, common, config) {
var vm = this;
//rest of the code omitted
The necessity of the IIFE here escapes me. One plausible explanation could be that without it, the line
var controllerId = "shell"
may fall under global scope (if my understanding is correct). Although I did experiment with removing the IIFE structure and found that it still functions properly, I have not been able to find a clear explanation in the AngularJS Style Guide. Could someone shed light on the advantages of adopting this approach?
P.S. If you believe this platform is not suitable for this query, kindly direct me to the appropriate place.