title: Why does an enum transpile into a function?
body: <p>Consider:</p>
  
  <pre><code>enum Colors {
      Red,
      Green,
      Blue
  }
  </code></pre>
  
  <p>It transpiles into this:</p>
  
  <pre><code>var Colors;
  (function (Colors) {
      Colors[Colors["Red"] = 0] = "Red";
      Colors[Colors["Green"] = 1] = "Green";
      Colors[Colors["Blue"] = 2] = "Blue";
  })(Colors || (Colors = {}));
  </code></pre>
  
  <p>Most questions about this result are answered in <em><a href="https://stackoverflow.com/questions/20278095/enums-in-typescript-what-is-the-javascript-code-doing">Enums in TypeScript: what is the JavaScript code doing?</a></em>.</p>
  
  <p>I quote the answers:</p>
  
  <blockquote>
    <p>This is an 'immediately executing function'</p>
  </blockquote>
  
  <p>And further down the topic:</p>
  
  <blockquote>
    <p>think they could probably just go:</p>
  
  <pre><code>var Colors;
  Colors || (Colors = {});
  Colors[Colors["Cyan"] = 3] = "Cyan";
  // ...
  </code></pre>
    
    <p>and skip the closure, but maybe I’m still missing something.</p>
  </blockquote>
  
  <p>So the question remains: why wrapping this in an immediately executing function?</p>