I've used setTimeout
plenty of times passing a function as a reference e.g.
setTimeout(someFunction, 3000);
In some cases, to preserve the value of this
I've had to assign it to a variable before hand, but don't understand why the following does not work:
var logger = {
log: function() {
var that = this;
console.log(that.msg);
setTimeout(that.log, 3000);
},
msg: "test"
};
logger.log();
Using an anonymous function however, does work:
var logger = {
log: function() {
var that = this;
console.log(that.msg);
setTimeout(function() { that.log() }, 3000);
},
msg: "test"
};