以下のようにメソッドを定義すると、thisがwindowになってしまう。
class Main
{
update(): void
{
requestAnimationFrame(this.update); //thisはwindow
}
}
以下のようにarrow functionを使って書くとwindowにならない。
class Main
{
update = () => {
requestAnimationFrame(this.update); //thisはMainオブジェクト
}
}
JSはthisの扱いが面倒だ。。
参考: