我知道这可能是痛苦的基本,但我很难把头绕过去。
class Main
{
constructor()
{
requestAnimationFrame(this.update); //fine
}
update(): void
{
requestAnimationFrame(this.update); //error, because this is window
}
}
似乎是我需要代理的情况,所以可以说使用 Jquery
class Main
{
constructor()
{
this.updateProxy = $.proxy(this.update, this);
requestAnimationFrame(this.updateProxy); //fine
}
updateProxy: () => void
update(): void
{
requestAnimationFrame(this.updateProxy); //fine
}
}
但是来自 Actionscript 3 背景,我不确定这里发生了什么。抱歉,我不确定 Javascript 从哪里开始,TypeScript 从哪里结束。
updateProxy: () => void
而且,我不相信我做对了。我想要的最后一件事是我的大部分班级都有需要访问的 aa() 函数,aProxy()
因为我觉得我正在写两次相同的东西?正常吗?