function in setInterval() executes without delay

≯℡__Kan透↙ 提交于 2019-11-27 09:33:34

http://jsfiddle.net/wWHux/3/

You called the function immediately instead of passing it to setInterval.

setInterval( change, 1500 ) - passes function change to setInterval

setInterval( change(), 1500 ) - calls the function change and passes the result (undefined) to setInterval

Where you have setInterval(change(), 99999999); you end up calling the change() function immediately and passing the return value of it to the setInterval() function. You need delay the execution of change() by wrapping it in a function.

setInterval(function() { change() }, 9999999);

Or you can delay it by passing setInterval() just the function itself without calling it.

setInterval(change, 9999999);

Either works. I personally find the first one a bit clearer about the intent than the second.

You have setInterval(change(), 99999999); and it should be setInterval(change, 99999999);. See the documentation of setInterval/setTimeout why. :)

Common mistake, happens to me all the time. :)

Change setInterval(change(), 99999999); to setInterval(change, 99999999);

And 99999999 means 99999999 milliseconds as you known.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!