title: Scoping of 'this' in TypeScript
body: <p>I have a very simple class, but already run into pain with the definition of ‘this’ in Typescript:</p>
  
  <p>Typescript</p>
  
  <pre><code>/// &lt;reference path='jquery.d.ts' /&gt;
  /// &lt;reference path='bootstrap.d.ts' /&gt;
  
  module Problem {
      export class Index {
          detailsUrl: string;
          constructor() {
              $('.problem-detail-button').click((e) =&gt; {
  
                  e.preventDefault();
  
                  var $row = $(this).closest('tr'); //this must be that of the callback
                  var problemId: number = $row.data('problem-id');
  
                  $.ajax({
                      url: this.detailsUrl, //this must be the instance of the class
                      data: { id: problemId },
                      type: 'POST',
                      success: (result) =&gt; {
                          $('#details-modal-placeholder').html(result);
                          $('#details-modal-placeholder modal').modal('show');
                      },
                  })
              });
          }
      }
  }
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>var Problem;
  (function (Problem) {
      var Index = (function () {
          function Index() {
              var _this = this;
              $('.problem-detail-button').click(function (e) {
                  e.preventDefault();
                  var $row = $(_this).closest('tr');
                  var problemId = $row.data('problem-id');
                  $.ajax({
                      url: _this.detailsUrl,
                      data: {
                          id: problemId
                      },
                      type: 'POST',
                      success: function (result) {
                          $('#details-modal-placeholder').html(result);
                          $('#details-modal-placeholder modal').modal('show');
                      }
                  });
              });
          }
          return Index;
      })();
      Problem.Index = Index;    
  })(Problem || (Problem = {}));
  </code></pre>
  
  <p>Now the problem is that the line</p>
  
  <pre><code>var $row = $(this).closest('tr'); //this must be that of the callback
  </code></pre>
  
  <p>and this line</p>
  
  <pre><code>this.detailsUrl, //this must be the instance of the class
  </code></pre>
  
  <p>conflict in the meaning of 'this'</p>
  
  <p>How do you handle the mixture of the 'this'?</p>