title: "this" keyword inside closure
body: <p>I've seen a bunch of examples but can't seem to get some sample code to work.</p>
  
  <p>Take the following code:</p>
  
  <pre><code>var test = (function(){
      var t = "test";
      return {
          alertT: function(){ 
              alert(t);
          }
      }
  }());
  </code></pre>
  
  <p>and I have a function on window.load like:</p>
  
  <pre><code>test.alertT();
  </code></pre>
  
  <p>That all works fine.  However, when I try to explicitly set the context of <em>t</em> inside the <em>alert()</em> in <em>alertT</em>, I just get undefined.</p>
  
  <p>I've tried:</p>
  
  <pre><code>var that = this;
  alert(that.t); //undefined
  </code></pre>
  
  <p>I've tried:</p>
  
  <pre><code>        return {
              that: this,
              alertT: function(){ 
                  alert(that.t); // undefined!
              }
          }
  </code></pre>
  
  <p>and I've tried:</p>
  
  <pre><code>var test = (function(){
      var t = "test";
      var myObj = this;
      return {
          alertT: function(){ 
              alert(myObj.t); // undefined!
          }
      }
  }());
  </code></pre>
  
  <p>what am I missing?  I need to be able to set the context explicitly for things like callbacks etc.  I've seen examples too (http://stackoverflow.com/questions/346015/javascript-closures-and-this-context) that seem like what I'm doing, so why does this not work?</p>