setInterval not working (Javascript)

后端 未结 1 1939
悲哀的现实
悲哀的现实 2021-01-26 12:03

I\'m trying to use setInterval in Javascript to redraw the canvas periodically. However, when I call the setInterval function, the function I pass to it only runs once. Here is

相关标签:
1条回答
  • 2021-01-26 12:52

    You should pass a function definition to the setInterval method, not the result of a function call.

    setInterval(function() {
      // Do something
    }, 1000);
    

    For your case,

    setInterval(function() {
      drawCanvas(ticTacToeBoard);
    }, 10);
    
    0 讨论(0)
提交回复
热议问题