下面的代码打印出来:
timedout false undefined
iethis
不再指theActivityTimer
in method timedOut()
。我想知道为什么会这样。
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/
有没有办法告诉它可以使用this