Typoskript "this" innerhalb einer Methode der Klasse

Ich weiß, dies ist wahrscheinlich schmerzhaft basic, aber ich bin eine harte Zeit Verpackung meinen Kopf um ihn herum.

class Main
{
     constructor()
     {
         requestAnimationFrame(this.update);  //fine    
     }

     update(): void
     {
         requestAnimationFrame(this.update);  //error, because this is window
     }

}

Scheint es der Fall zu sein, dass ich einen proxy benötigen, also sagen wir, dass die Verwendung von Jquery

class Main
{
     constructor()
     {
         this.updateProxy = $.proxy(this.update, this);
         requestAnimationFrame(this.updateProxy);  //fine    
     }

     updateProxy: () => void
     update(): void
     {
         requestAnimationFrame(this.updateProxy);  //fine
     }

}

Aber aus einer Actionscript-3-hintergrund, ich bin nicht wirklich sicher, was hier passiert. Sorry, ich bin nicht sicher, wo Javascript beginnt und Typoskript endet.

updateProxy: () => void

Und ich bin auch nicht überzeugt, ich mache das richtige. Das Letzte was ich will ist die meisten meiner Klasse haben ein eine () - Funktion muss aufgerufen werden, mit aProxy() wie ich finde, Schreibe ich die gleiche Sache zweimal? Ist es normal?

Ich fand diese Dokumentation sehr hilfreich github.com/Microsoft/TypeScript/wiki/...

InformationsquelleAutor Clark | 2013-04-22

Schreibe einen Kommentar