[英]setTimeout causing Uncaught TypeError: number is not a function
so I'm declaring blank variables outside of functions. 所以我要在函数之外声明空白变量。
//To be Timeouts
var progressionTimer;
var nextTimer;
var cycleTimer;
and then within functions 然后在功能内
progressionTimer = setTimout(loadNextFunction, 2000);
progressionTimer();
nextTimer = setTimeout(loadOutsideFunction, 2000);
nextTimer();
//etc
however every time one of those declaration is called 但是每次调用其中一个声明
nextTimer();
my console in chrome/firefox/etc fills with this 我的控制台在chrome / firefox / etc中充满了
Uncaught TypeError: number is not a function
it functions absolutely as intended and clearTimeout works without issue, but the console error is just frustrating me, can anyone solve this without loosing the funcitonality and still having clearTimeout work? 它的功能完全符合预期,并且clearTimeout可以正常工作,但是控制台错误让我感到沮丧,任何人都可以在不失去功能性的情况下解决此问题,并且仍然可以使用clearTimeout吗?
setTimeout
returns a handler, an ID that lets you reference the timeout so you can clear it with clearTimeout
, which is a number. setTimeout
返回一个处理程序,一个可以让您引用超时的ID,以便您可以使用数字clearTimeout
清除它。
It does not return a function that can be executed, and that is the problem, you're trying to execute the return value of setTimeout
它不返回可以执行的函数,这就是问题所在,您正在尝试执行setTimeout
的返回值
nextTimer = setTimeout(loadOutsideFunction, 2000);
nextTimer(); // not a function, but a number referencing the timeout ?
clearTimeout(nextTimer); // works just fine
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.