How to make that in the animate self function refer to the Animation instance, and not to the window, without resorting to cloning the function inside the Animation?
var Animation = function (frameCount_) { var self = this; this.image = image_; this.frameCount = frameCount_; this.i = 1; this.x = 0; this.y = 0; this.animateTimer = 0; this.start(); } Animation.prototype.start = function () { clearInterval(this.animateTimer); setInterval(this.animate, 50); } Animation.prototype.stop = function () { clearInterval(this.animateTimer); } Animation.prototype.animate = function () { if (self.i < self.frameCount) { self.i++; } else { self.i = 1; } self.x = (self.i - 1) * 50; }