Still confused about JavaScript's 'this'
<p>I've been reading through quite a few articles on the 'this' keyword when using JavaScript objects and I'm still somewhat confused. I'm quite happy writing object orientated Javascript and I get around the 'this' issue by referring the full object path but I don't like the fact I still find 'this' confusing. </p>

<p>I found a good answer <a href="http://stackoverflow.com/questions/2148451/help-this-is-confusing-me-in-javascript">here</a> which helped me but I'm still not 100% sure. So, onto the example. The following script is linked from test.html with <code>&lt;script src="js/test.js"&gt;&lt;/script&gt;</code></p>

<pre><code>if (!nick) {
    var nick = {};
}

nick.lowman = function(){
    var helloA = 'Hello A';
    console.log('1.',this, this.helloA);

    var init = function(){
        var helloB = 'Hello B';
        console.log('2.',this, this.helloB);
    }

    return {
        init: init
    }
}();

nick.lowman.init();
</code></pre>

<p><strong>What kind of expected to see was</strong> </p>

<pre><code>1. Object {} nick.lowman, 'Hello A'
2. Object {} init, 'Hello B'
</code></pre>

<p><strong>But what I get is this?</strong></p>

<pre><code>1. Window test.html, undefined
2. Object {} init, undefined
</code></pre>

<p>I think I understand some of what's happening there but I would mind if someone out there explains it to me.</p>

<p>Also, I'm not entirely sure why the first 'console.log' is being called at all? If I remove the call to the init function <code>//nick.lowman.init()</code> firebug still outputs <code>1. Window test.html, undefined</code>. Why is that? Why does  nick.lowman() get called by the window object when the html page loads? </p>

<p>Many thanks</p>
