Javascript self calling anonymous function for scope closure
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5020479/what-advantages-does-using-functionwindow-document-undefined-windo">What advantages does using (function(window, document, undefined) { … })(window, document) confer?</a>  </p>
</blockquote>



<p>I'm increasingly seeing code like this in libraries I've been using:</p>

<pre><code>(function (window) {
    var Foo = function () {
    }

    window.Foo = Foo;
})(window);
</code></pre>

<p>The argument I've seen for doing this is to avoid working in the global scope when creating (pseudo) classes. But, correct me if I'm wrong, I always understood that window IS the global scope. I believe, when you create a global variable, you are really only adding a property to window anyway... Unless this is changing for ES5 strict?</p>

<p>So, basically, what's the point? The only benefit I can see to code organised like this is if you wanted to easily change the namespace of your classes at a later date by passing in an argument other than window.</p>
