Why does `this` change when passing the function argument as string or reference?
<p>Have a look at this...</p>

<pre><code>var a = {
    b: function() {
      console.log(this); 
    }  
}

// Example 1
a.b(); // a

// Example 2    
eval('a.b()'); // a

// Example 3
setTimeout('a.b()', 100); // a

// Example 4
setTimeout(a.b, 100); // Window

// Example 5
var c = a.b;
c(); // Window
</code></pre>

<p><a href="http://jsfiddle.net/alexdickson/7RG76/" rel="nofollow">jsFiddle</a>.</p>

<p>Assuming the <em>expected result</em> is what <em>I</em> expected...</p>

<h3>Example 1</h3>

<p>When calling <code>b()</code>, the property of an <code>Object</code>, <code>this</code> becomes the property's <code>Object</code>, here it's the parent <code>a</code>. It produces the expected result.</p>

<h3>Example 2</h3>

<p><code>eval()</code> is meant to adopt its execution context of where it is called, in this case, <code>window</code>. It also produces the expected result.</p>

<h3>Example 3</h3>

<p>When passing a string to <code>setTimeout()</code>, I'd imagine it is ran through something very similar to <code>eval()</code>. It too produces the expected result.</p>

<h3>Example 4</h3>

<p><code>this</code> becomes <code>Window</code> in this example. This is what I am interested in.</p>

<h3>Example 5</h3>

<p>Here the <code>this</code> becomes <code>Window</code>, because <code>c</code>'s parent object is <code>Window</code>.</p>

<ol>
<li><p>When passing only a reference to a function (e.g. <code>a.b</code>), will its <code>this</code>  always be <code>Window</code> when called with <code>()</code>? </p></li>
<li><p>Is the only way to keep its <code>this</code> as <code>a</code> to pass it as a string to <code>setTimeout()</code> / <code>setInterval()</code>?</p></li>
</ol>

<p>Thanks.</p>
