title: Unable to use "class" methods for callbacks in JavaScript
body: <p>I'm having a really rough time wrapping my head around prototypes in JavaScript.</p>
  
  <p>Previously I had trouble calling something like this:</p>
  
  <pre><code>o = new MyClass();
  setTimeout(o.method, 500);
  </code></pre>
  
  <p>and I was told I could fix it by using:</p>
  
  <pre><code>setTimeout(function() { o.method(); }, 500);
  </code></pre>
  
  <p>And this works. I'm now having a different problem, and I thought I could solve it the same way, by just dropping in an anonymous function. My new problem is this:</p>
  
  <pre><code>MyClass.prototype.open = function() {
      $.ajax({
          /*...*/
          success: this.some_callback,
      });
  }
  
  MyClass.prototype.some_callback(data) {
      console.log("received data! " + data);
      this.open();
  }
  </code></pre>
  
  <p>I'm finding that within the body of <code>MyClass.prototype.some_callback</code> the <code>this</code> keyword doesn't refer to the instance of <code>MyClass</code> which the method was called on, but rather what appears to be the jQuery ajax request (it's an object that contains an xhr object and all the parameters of my ajax call, among other things).</p>
  
  <p>I have tried doing this:</p>
  
  <pre><code>$.ajax({
      /* ... */
      success: function() { this.some_callback(); },
  });
  </code></pre>
  
  <p>but I get the error:<br>
  <code>Uncaught TypeError: Object #&lt;an Object&gt; has no method 'handle_response'</code></p>
  
  <p>I'm not sure how to properly do this. I'm new to JavaScript and the concept of prototypes-that-sometimes-sort-of-behave-like-classes-but-usually-don't is really confusing me.</p>
  
  <p>So what is the right way to do this? Am I trying to force JavaScript into a paradigm which it doesn't belong?</p>