【发布时间】:2013-04-15 23:43:07
【问题描述】:
我知道这可能是非常基本的,但我很难理解它。
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
而且,我不相信我这样做是正确的。我想要的最后一件事是我的大部分班级都有一个需要使用aProxy() 访问的 a() 函数,因为我觉得我正在写两次相同的东西?正常吗?
【问题讨论】:
-
我发现这个文档很有帮助github.com/Microsoft/TypeScript/wiki/…
标签: jquery this typescript proxy-classes