title: Execution context of setTimeout (JavaScript)
body: <p>1) Can someone illustrate how setTimeout works in terms of execution threads.</p>
  
  <p>Consider:</p>
  
  <pre><code>function foo() { alert('foo'); }
  function bar() { alert('bar'); }  
  setTimeout(foo,1000);
  bar();
  </code></pre>
  
  <p>or </p>
  
  <pre><code>function foo() { alert('foo'); setTimeout(foo,1000); }
  function bar() { alert('bar'); }  
  setTimeout(foo,1000);
  bar();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>function foo() { alert('foo'); setTimeout(foo,1000); }
  function bar() { /* an execution that runs with unknown time */ }  
  setTimeout(foo,1000);
  bar();
  </code></pre>
  
  <p>or </p>
  
  <pre><code>function foo() { alert('foo'); setTimeout(foo,1000); }
  function bar() { /* some ajax call that reply with unknown time */ }  
  setTimeout(foo,1000);
  bar();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>function foo() { alert('foo'); setTimeout(foo,1000); }
  function bar() { alert('foo'); setTimeout(bar,1000); }  
  setTimeout(foo,1000);
  setTimeout(bar,1000);
  </code></pre>
  
  <p>2) Can someone explain how why "this" object doesn't work in setTimeout and what we can do to get around that problem?</p>