What is the correct way to reference an object function from within itself, so that I can call it several times using setTimeout in Javascript? In other words I want to be able to do this:
Foo.prototype.move = function() {
if (this.count_a < 5) {
this.count_a += 1;
// setTimeout(this.move, 500); // doesn't work
// setTimeout(function() { this.move(); }, 500); // doesn't work
}
}
I have tried a couple of things, none of which seem to work: http://jsfiddle.net/tga8r/1/