title: bind function and this in typescript
body: <p>I wanted to implement a simple context binding but it doesn't work in TypeScript.
  Here is my piece of code:</p>
  
  <pre><code>class Engine {
      // some code...
  
      spriteController(sprite: Sprite, callbackfn: (ctx: CanvasRenderingContext2D) =&gt; void) {
          callbackfn.bind(new SpriteController(sprite), [this._ctx]);
      }
  
      // code again ...
  }
  </code></pre>
  
  <p>If I want to use spriteController method in another file like this:</p>
  
  <pre><code>engine.spriteController(sprite, function(ctx) {
      this.moveRight() // access to the spriteController class
  })
  </code></pre>
  
  <p>I want to be able to use the SpriteController class within the callback. <br /> 
  In JS, the first argument (within the bind() call) bind 'this' to the given object. But in TypeScript, functions created from function.bind are always preserve 'this'. <br />
  How to achieve this in TypeScript?</p>