title: How do I make this. work with promises and generic functions
body: <p>I am trying to do something rather like the following:</p>
  
  <pre><code>function newCounter(){
      return {
          "counter" : 0
          ,"mode" : "new"
          ,"start" : function( arg_function ){
              //    Run this before counting.
              this.counter = 0;
              this.mode = "count";
          }
          ,"finished" : function(){
              // Run this when counting is no longer allowed.
              this.mode = "done";
          }
          ,"increment" : function(arg_key){
              globalThing.isValid(arg_key)
              .done(function(data){
                  if( this.mode === "count" ){
                      this.counter++;
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>Now, the problem here, as one may notice, is that inside the <code>.done()</code> section there, I have a reference to <code>this.</code> - which does not and cannot refer to the object in question because it's inside a promise with a generic function, and as such, refers to <code>window.</code> and not the specific object being referenced from.  I have tried these:</p>
  
  <pre><code>.done(function(data){
      if( this.mode === "count" ){
          this.counter++;
      }
  }.apply(this))
  
  .done(function(data){
      if( this.mode === "count" ){
          this.counter++;
      }
  }.call(this))
  </code></pre>
  
  <p>as solutions, but they have not succeeded.  I'm not entirely sure why.  If you can see what I'm trying to do here ... could you recommend, please, a solution to my woes?</p>