0

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);
        }
    }
nalaiqChughtai
  • 1,179
  • 2
  • 9
  • 15
  • 1
    Hi! Please put your runnable example **here, on-site** using Stack Snippets (the `[<>]` toolbar button), not off-site. [Here's how to do one](https://meta.stackoverflow.com/questions/358992/). Three reasons: People shouldn't have to go off-site to help you; some sites are blocked for some users; and links rot, making the question and its answers useless to people in the future. – T.J. Crowder Aug 19 '21 at 10:16
  • 1
    Please review the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) I also recommend Jon Skeet's [Writing the Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and [Question Checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). What specifically are you asking about? What variable? What value are you seeing? What value do you expect instead? – T.J. Crowder Aug 19 '21 at 10:17

0 Answers0