0
function play()
{
if (typeof Game_Interval != "undefined")
clearInterval(Game_Interval);
Game_Interval = setInterval(paint, 60);
allowPressKeys = true;
}

What exactly is Game_Interval and why isnt it declared as a variable in the code? The above mentioned function is a part of a snake game program using javascript and HTML canvas tag.

1
  • Game_Interval is likely some kind of JavaScript object on which clearInterval and setInterval operate. Of course, there's no way to know without seeing all the code. You've shared only a small part out of context. Commented Apr 8, 2017 at 4:48

1 Answer 1

0

setInterval calls a function (paint() in your case) at regular intervals (60ms in your case) and returns a Number, representing the ID value of the timer that is set. Use this value with the clearInterval() method to cancel the timer.

Since Game_Interval is not declared, javascript will implicitly declare it as a global variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Makes sense. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.