title: How can I keep the context of 'this' in jquery
body: <p>I have something like this:</p>
  
  <pre><code>var Something = function(){
    this.render = function(){};
    $(window).resize(function(){
      this.render();
    });
  }
  </code></pre>
  
  <p>The trouble is that inside the anonymous function 'this' refers to the window object. I know I could do something like:</p>
  
  <pre><code>var Something = function(){
    this.render = function(){};
    var tempThis = this;
    $(window).resize(function(){
      tempThis.render();
    });
  }
  </code></pre>
  
  <p>but is there a better way? This doesn't look very elegant.</p>