title: Why doesn't this closure have access to the 'this' keyword? - jQuery
body: <p>I'm a beginner to closures (and Javscript in general), and I can't find a satisfactory explanation as to what's going on in this code:</p>
  
  <pre><code>function myObject(){
      this.myHello = "hello";
      this.myMethod = do_stuff;
  }
  
  function do_stuff(){
      var myThis = this;
      $.get('http://example.com', function(){
          alert(this.myHello);
          alert(myThis.myHello);
      });
  }
  
  var obj = new myObject;
  obj.myMethod();
  </code></pre>
  
  <p>It will alert 'undefined' and then 'hello'. Obviously this should not be jQuery specific, but this is the simplest form of my original code I could come up with. The closure in <code>do_stuff()</code> has access to the variables in that scope, but apparently this rule does not apply to the <code>this</code> keyword.</p>
  
  <p>Questions:</p>
  
  <p>What happens to <code>this</code> when the closure is passed outside the scope of <code>do_stuff()</code> (in this case <code>$.get()</code>)? Does <code>myThis</code> contain a copy of <code>this</code> or a reference to it? Is it generally not a good idea to use <code>this</code> in closures?</p>
  
  <p>Any response much appreciated.</p>