Please anyone help me to find whats wrong with the below code. checkInSessionTimout constructor being called at code-CreateObject but the variables values are not retaining at code-setInterval.
https://jsfiddle.net/y1f74tz8/2/
var _timer;
function addIdleCheckInMethod() {
var sessionTimeout = new checkInSessionTimout(); //**code-CreateObject**
$(this).mousemove(sessionTimeout.resetTimer);
$(this).keypress(sessionTimeout.resetTimer);
/* _timer = setInterval(function () { sessionTimeout.checkIdleTime(onSessionExpire) }
, 1000);
*/
_timer = setInterval(sessionTimeout.checkIdleTime //**code-setInterval**
, 1000, onSessionExpire);
}
function onSessionExpire() {
clearInterval(_timer);
var user = new user();
console.log('session expired!');
}
class checkInSessionTimout {
constructor(args){
this.IDLE_TIMEOUT = args != null && args.idleTimout ? args.idleTimout : 30;
this._idleSecondsCounter = 0;
console.log('constructor');
}
checkIdleTime(callback) {
this._idleSecondsCounter++;
console.log( "idle timeout: " + this.IDLE_TIMEOUT + ' counter: ' + this._idleSecondsCounter);
if (this._idleSecondsCounter >= this.IDLE_TIMEOUT) {
callback();
}
}
resetTimer() {
this._idleSecondsCounter = 0;
console.log('reset:' + this._idleSecondsCounter);
}
}