JS: var self = this?
<p>Using instance methods as callbacks for event handlers changes the scope of <code>this</code> from <em>"My instance"</em> to <em>"Whatever just called the callback"</em>. So my code looks like this</p>

<pre><code>function MyObject() {
  this.doSomething = function() {
    ...
  }

  var self = this
  $('#foobar').bind('click', function(){
    self.doSomethng()
    // this.doSomething() would not work here
  })
}
</code></pre>

<p>It works, but is that the best way to do it? It looks strange to me.</p>
