The code below prints out:
timedout false undefined
I.e. this is no longer refering to theActivityTimer in method timedOut(). I was wondering why this was.
var theActivityTimer = {
timer: "",
active: false,
refresh: function () {
theActivityTimer.timer = setTimeout(
this.timedOut,
5000
);
},
timedOut: function(){
alert("timedout " +
theActivityTimer.active + " " + this.active);
}
}
theActivityTimer.refresh();
http://jsfiddle.net/spiderplant0/nQ4XX/
And is there a way to tell get it to work with this
thisis how a function is invoked.