I’m using window.setInterval, and it must have to be able to access a method that is defined in a “class”, but since setInterval is in a scope separate from the method it was defined in, this resolves to window instead of the desired instance of Game. What code can I use to get the desired behaviour of calling Game.update instead of window.update?
(That looks kind of confusing. Maybe the following incorrect code can clear things up a bit.)
game = function () {
/* ... */
this.update = function () {
/* ... */
}
this.interval = window.setInterval(this.update /* !!! */, 50);
}
This can be done without a JS framework.