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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:32:27+00:00 2026-06-10T19:32:27+00:00

I have a variable created with setInterval called cycle1 . It is created with

  • 0

I have a variable created with setInterval called cycle1. It is created with setInterval inside of a prototyped function to an object called eGi, which is the same as $_. After creating it, it still fires, but is inaccessible to the rest of the script and the console. When I try to clear this interval from another prototyped function, nothing happens.

eGi.prototype.startGame = function() {
    //other code...
    if (somethingOrOther) { 
        var somethingElse = confirm("start interval?");
        if (somethingElse) {
            this.cycle1 = setInterval($_.cycle,toMS(INTERVAL_SECONDS));
        }
    } else {
        this.cycle1 = setInterval($_.cycle,toMS(INTERVAL_SECONDS));
    }
};

then when i try and stop it in another function

eGi.prototype.gameOver = function() {
    clearInterval(this.cycle1);
    //other code...
    if (restart) {
        $_.startGame();
    } else {
        $_.mainMenu();
    }
};

It never gets cleared, and seems to be created again in the calling of $_.startGame. I can’t even access it from the Chrome console using $_.cycle1 or the eGi instance variable, egi.cycle1. The strange thing is, this works for accessing any other variable that belongs to my eGi object:

var eGi = function(console,cDom,ctxt,game,devMode) {
    $_ = this;
    this.game = game;
    this.cDom = cDom; //specifically, these objects control the canvas' DOM
    this.ctxt = ctxt; //and the CanvasRenderingContext2D
}
eGi.prototype.mainMenu = function() {
    this.ctxt.fillText("Hello",250,250); //this works just fine
    //etc
};

Why isn’t it being cleared?

Full code/game here.

  • 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-10T19:32:28+00:00Added an answer on June 10, 2026 at 7:32 pm

    It’s a nice game…

    The problem is you are referring to “this” inside gameover which doesn’t contain reference to cycle1 (undefined).

    Instead you have to store “cycle1” as part of an object which can be referenced from your other function (in this case gameover)

    Making variables as global is not a good thing. Instead you can store the “cycle1” as part of eGi or any such namespace or object.

    Refer here (working code): JSFiddle implementation

    Javascript code (start and stop are input buttons)

    var eGi = {};
    
    $('#start').click(function start() {
    var somethingElse = confirm("start interval?");
    if (somethingElse) {
        eGi.cycle1 = setInterval(function(){
            console.log('Running...');
        },1000);
    }
    });
    
    $('#stop').click(function stop(){
          clearInterval(eGi.cycle1);
        });
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of class object that I created as a variable in
I have created a Variable called myDBManager in my AppDelegate: @interface myAppDelegate : NSObject
I have a dynamically created variable called item_908 (where 908 is dynamically). Later on,
I have created a variable and tried to set its value by a function.
I have created a servlet that passes a string variable strname to a JSP
I have a workflow that is created in code and a variable of type
I have an app that creates a variable number of ScatterviewItems based on which
I have a javascript function create(tagName, options) and the options variable is a JSON
i have a php file which stores a variable, and i need to create
Is it possible a lambda function to have variable number of arguments? For example,

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.