我有一个我试图用来管理客户端会话的类,它看起来像这样:
var sessionmanager;
sessionmanager = (function() {
sessionmanager.name = 'sessionmanager';
function sessionmanager(timeout, action) {
if (action != null) {
this.action = action;
} else {
this.action = null;
}
if (timeout != null) {
this.timeout = timeout * 60;
} else {
this.timeout = 0;
}
}
sessionmanager.prototype.run = function() {
return window.setInterval(this.tick, 1000);
};
sessionmanager.prototype.sessionExpired = function() {
if (this.action != null) {
window.navigate("timeout.asp");
}
};
sessionmanager.prototype.setTimeout = function(timeout) {
return this.timeout = timeout;
};
sessionmanager.prototype.tick = function() {
this.timeout -= 1;
if (this.timeout < 1) {
return sessionExpired();
}
};
return sessionmanager;
})();
tick
但是,当我在从回调中调用的函数内部进行调试时,setInterval
我得到this.timeout = NaN
我猜我的范围不正确?请帮忙?我是javascript新手...