title: Wrong "this" when calling a superclass method from a callback in a subclass in TypeScript
body: <p>I've got some TypeScript code that (effectively) looks like this:</p>
  
  <pre><code>class User {
      name: string = "Bob";
      sayHello(): void {
          console.log("Hello, " + this.name);
      }
  }
  
  class RegisteredUser extends User {
      name: string = "Frank";
      sayHello(): void {
          var s = super;
          setTimeout(() =&gt; s.sayHello(), 1000);
      }
  }
  
  var registeredUser = new RegisteredUser();
  registeredUser.sayHello();
  </code></pre>
  
  <p>The problem is that TypeScript (inexplicably, IMO) follows the weird JavaScript rules about "this" instead of doing it how every other programming language in the world does it. And so when User.sayHello() is called from the override in RegisteredUser.sayHello(), the <code>this</code> points to the User <em>class</em> rather than to the instantiated RegisteredUser <em>object</em>, so that what is actually logged is:</p>
  
  <pre><code>Hello, undefined
  </code></pre>
  
  <p>Beyond the fact that this doesn't make any sense to me to do it this way (see <a href="https://typescript.codeplex.com/workitem/477" rel="nofollow">https://typescript.codeplex.com/workitem/477</a>), what's the best way to work around this, so that <code>this</code> in User.sayHello() is pointing to the right object when called from a callback?</p>