You've not added update
to the prototype. The value of this
in that method will be most likely the window
object.
Change your call from this:
update();
To this:
update.call(this);
Or add update
to the .prototype
:
Jsloth.prototype.update = update;
and use:
this.update();
But if you're going to call update()
from the setInterval()
, you'll need to ensure the proper this
value.
To do that, you can pass an anonymous function, and keep a reference to the outer this
value in a variable.
var exec = function () {
this.x = 0;
this.y = 0;
var that = this;
setInterval(function() {
that.update();
//update.call(that); // if you didn't add update() to the .prototype
}, 1000/10);
};