【发布时间】:2020-02-28 16:49:08
【问题描述】:
我需要在 3 和 5 的倍数之后更改此 javascript 函数中的时间间隔,但这没有发生。 怎么了? 为此,最好使用“setInterval”还是“setTimeout”? 谢谢!
//index.js
var countx = 1;
var multiplox = 2500;
function intervalFunc() {
console.log('Cant stop me now! ', countx, multiplox);
if (countx % 3 === 0) {
const timeoutObj = setTimeout(() => {
console.log('timeout beyond time 3');
}, 1500);
}
if (countx % 5 === 0) {
const timeoutObj = setTimeout(() => {
console.log('timeout beyond time 5');
}, 20000);
}
countx++;
}
setInterval(intervalFunc, 4000);
【问题讨论】:
-
countx是否在改变值?将其作为参数传递可能会更好 -
那么究竟需要改变什么?间隔中的时间 (
4000)、第一个 'if' 语句中的时间 (1500) 或第二个 'if' 语句中的时间 (20000)???... 期望的结果这里不是很清楚。 -
您的预期结果是什么?
标签: javascript node.js time