Reputation: 483
I have two setInterval each running a function every 20s. Is there a way to put both functions under the same setInterval call?
setInterval(function(){
//function a
}, 20000);
setInterval(function(){
//function b
}, 20000);
To something like:
setInterval( (functionA, functionB) , 20000);
Upvotes: 10
Views: 19017
Reputation: 24638
If you define a third function that calls the two functions, you can just call that third function as follows:
function functionC() {
functionA();
functionB();
}
setInterval( functionC, 20000 );
Upvotes: 5
Reputation: 388316
Just call both the functions within another callback function like
setInterval(function () {
functionA();
functionB();
}, 20000);
Upvotes: 23