JavaScript and 'this' inside immediately executed functions
<p>I have been reading up on the intricacies of 'this' in JavaScript. Given this code:</p>

<pre><code>$(document).ready(function() {
    console.dir(this);
    (function foo() {
        console.dir(this);
    })();
});
</code></pre>

<p>In Chrome, the console shows the first 'this' as an 'HTMLDocument' (as I expected), but the second 'this' is 'undefined'. Can someone point me to a good explanation of why?</p>
