title: Why are functions on the object being executed from a self executing function?
body: <p>I have an application that in debug mode is written in many separate javascript files, but are loaded synchronously as part of the head block of a page.  In release, I merge all these files together and minifiy them. Today I kept finding an error in the minified version, so I loaded up a single merged file to debug the issue and found that one library was self executing a function and it was causing other functions defined on <code>window</code> to be executed.  </p>
  
  <p>I've repo'd the behavior here with a generic object, doesn't matter if its window or not:</p>
  
  <pre><code>&lt;head&gt;
      &lt;script&gt;
          var a = {}
  
          a.X = function x(){
              console.log("shouldn't be executed");
          }
  
          (function(a){
              console.log("self execution");
          }(a));
       &lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>In this example, I get the output of</p>
  
  <pre><code>self execution 
  shouldn't be executed 
  </code></pre>
  
  <p>If I change the call to be</p>
  
  <pre><code>&lt;head&gt;
      &lt;script&gt;
          var a = {}
  
          function x(){
              console.log("shouldn't be executed");
          }
  
          a.X = x;
  
          (function(a){
              console.log("self execution");
          }(a));
       &lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>Then I just get </p>
  
  <pre><code>self execution
  </code></pre>
  
  <p>Which is what I expected.  In the first example, why is <code>X</code> getting called when <code>a</code> is passed to the self executing function?</p>