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 7876669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:12:09+00:00 2026-06-03T03:12:09+00:00

Background: I’ve written a javascript object called Step to implement a step-type event for

  • 0

Background:
I’ve written a javascript object called Step to implement a step-type event for any operation I might need to use for my website, e.g. smooth-motion functions. I can register functions in it to run each step by using the Step object’s method, registerFunction(func).

To handle running the functions every step, the Step object has another method called run().
In this method I run through the list of registered functions, run them, and then call the setTimeout(...) function, passing the reference to the run function to recall it for the next step.

Problem:
The first ‘step’ is run by the onload event (attribute) in the <body> tag of my html page (indirectly, though: Step.run is called by a function initiateJS() which is called by onload). Nothing goes wrong in the first step. However, by the second step, the variables within the Step object seem to have been disposed; they all become undefined.

Questions:
I was thinking it might be due to the garbage collector? Maybe it somehow loses its reference?
Also, is using setTimeout(...) even the best method of making a step-type event implementation?

Details:
The Step object is declared in the js document somewhat as:

    var Step = {
            myVars: "somevalues",
            anArray: [],
            run: function() {
                //run the registered functions
                setTimeout(this.run,this.interval);
        };

ALSO, in the next step, the Step object is still existent.

Some other minor details:

  • I’m using Chrome
  • I’m making my website with XAMPP full
  • I’m using Windows 7
    • 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-03T03:12:10+00:00Added an answer on June 3, 2026 at 3:12 am

      setTimeout runs code in the global context. this is no longer defined the next time run() executes. You’ll need to refactor your code to either declare variables on some kind of global object, or to pass references into the run function itself.

      edit: since you said Step is global, this should work:

      run: function() {
          //run the registered functions
          setTimeout(Step.run, Step.interval);
      }
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    Background Use Ajax to fire an event to the web server when a list
    Background: As a short project over winter break, I'm trying to implement a programming
    Background I'm trying to implement a simple web server part as a web interface
    Background We currently use OpenID for authentication of users, and use the Claimed Identity
    Background We have an asp.net 4.0 web application written in C# that calls a
    Background: I need to reserve an amount of memory below 0xA0000 prior to my
    Background I am trying to create a copy of a business object I have
    Background I have a pair of functions I want to use to animate some
    Background: Big project with multiple packages. Resources need to be shared among packages I
    Background: I am a beginner javascript developer who is trying to understand and learn

    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.