title: Javascript module pattern, scope and "this"
body: <p>I'm trying to wrap my head around building a custom JavaScript library. I've read a lot about the module pattern, and also read Crockford's articles on private and public members. I know what is an immediately invoked function expression and why we do stuff like</p>
  
  <pre><code>var myLib = (function() {
  }())
  </code></pre>
  
  <p>However, I'm still a little lost in some cases regarding scope and closures in general. The concrete problem I have is:</p>
  
  <p>Why does the following example alert DOMWindow, rather than the myLib object?
  <a href="http://jsfiddle.net/slavo/xNJtW/1/" rel="nofollow">http://jsfiddle.net/slavo/xNJtW/1/</a></p>
  
  <p>It would be great if you can explain what "this" refers to in all of the methods in that example and why.</p>