简体   繁体   English

setTimeout导致未捕获的TypeError:number不是函数

[英]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.

相关问题 是什么导致错误“未捕获的TypeError:数字不是函数” - What is causing the error “Uncaught TypeError: number is not a function” 是什么导致Uncaught TypeError:number不是函数? - What is causing Uncaught TypeError: number is not a function? 未捕获的TypeError:number不是函数 - Uncaught TypeError: number is not a function 未捕获的TypeError:number不是函数 - Uncaught TypeError: number is not a function 未捕获的类型错误:$.number 不是 function - Uncaught TypeError: $.number is not a function Javascript:未捕获类型错误:window.setTimeout(...) 不是 function - Javascript: Uncaught TypeError: window.setTimeout(…) is not a function setTimeout()返回Uncaught TypeError - setTimeout() returns Uncaught TypeError JavaScript错误 - 未捕获TypeError :(中间值).toLocaleTimeString(...)。setTimeout不是函数 - JavaScript error- Uncaught TypeError: (intermediate value).toLocaleTimeString(…).setTimeout is not a function Webpack:Bundle.js-未捕获的TypeError :(中间值).setTimeout不是函数 - Webpack: Bundle.js - Uncaught TypeError: (intermediate value).setTimeout is not a function 执行后,window.setTimeout()引发“未捕获的TypeError:未定义不是函数”? - after executing, window.setTimeout() throws 'Uncaught TypeError: undefined is not a function'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM