Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:20:26+00:00 2026-06-06T22:20:26+00:00

I have a class I am attempting to use to manage a session on

  • 0

I have a class I am attempting to use to manage a session on the client side, it looks like this:

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;

})();

However when I debug inside the tick function that is called from within the setInterval callback I get this.timeout = NaN

I am guessing I scoped something incorrectly? Help please? I am new to javascript…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:20:27+00:00Added an answer on June 6, 2026 at 10:20 pm

    If setInterval calls the function it doesn’t set the this value as you may expect. Calling this.tick() does set it correctly, but just passing the function and having it called in another way does not. You have to bind the this value to what you want:

    setInterval(this.tick.bind(this), 1000);
    

    This is available on newer browsers but there are shims available.

    Also, you probably meant this.sessionExpired(), as that’s where it’s defined. return doesn’t make much sense there since setInterval does not care about the return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to use the ReaderWriterLockSlim class to manage a list. There are many
We are attempting to use VS2008 Class Designer for a UML-like class diagram. However,
I am attempting to select all a hrefs that do not have the class
Using VS2008 C# am attempting to interop a C++ dll. Have a C++ class
I have class Meat extends Food { $var = Food::foodFunction… } I need to
I have a class EventArgs(Of T) in my solution. This class is located in
i'm attempting to use apache tomcat 7.0 tomcat7 to access java servlets. I have
I have been attempting to use the command line tool crmsvcutil (as Administrator) to
I have been attempting to use an android.preference.DialogPreference inflated from XML, but the documentation
I have been having trouble while attempting to use the nextLine() method from java.util.Scanner.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.