title: JQuery deferred changes "this"
body: <p>I'm attempting to have a javascript object run a deferred method and when it's .done() call a function in that same object.  I'm having issues because "this" becomes the deferred object instead of the object that called it.</p>
  
  <pre><code>PageObject.prototype.successFunction = function() {
    console.log(arguments);
    return console.log(this.name + " Success function called");
  };
  
  PageObject.prototype.loadPage = function(url) {
    return $.when($.mobile.loadPage("pages/" + url))
      .done(this.successFunction);
  };
  
  var pg = new PageObject();
  pg.loadPage("test.html");
  </code></pre>
  
  <p>How do I send "this" into the successFunction?  This PageObject is going to be extended by others as well, so knowing "this" when running successFunction will be very handy.</p>
  
  <p>It seems simple, and probably has a simple answer.  I was looking into .apply() but I'm not sure it helped.  This post on stack overflow was helpful a little bit, but it broke the minute I put it into the .done() function.</p>
  
  <p><a href="https://stackoverflow.com/questions/737802/functions-as-parameters-with-parameters-javasript">Functions as parameters (with parameters) -- JavaScript</a></p>