title: is using window.onload to execute an anonymous function the same base principle as the module pattern?
body: <p>when using the module pattern in js i've notice that the main benefits are private members and not cluttering the global namespace, but what i wanted to know is, is this:</p>
  
  <pre><code>(function(){
     //some code...
  })(); 
  </code></pre>
  
  <p>the same as this:</p>
  
  <pre><code>window.onload = function(){
      //some code...
  }
  </code></pre>
  
  <p>they both provide private members and both don't clutter the global namespace. the only difference i can see is that if both are manipulating DOM elements the second one can be called anywhere within the document (because of document.onload) while the first has to be called ether at the bottom of the body node or right after the close of the body node.</p>
  
  <p>are there any other differences between the two that i may be missing?</p>