0

Below code, will delay 10 second then execute the function A and B first time.

setInterval(function () {
    A();
    B();
}, 10000);

I wanna execute A and B at the program run at the same time. Like,

A();
B();
setInterval(function () {
    A();
    B();
}, 10000);

There is no better way to do it?


Thanks all.

Salmon
  • 133
  • 3
  • 11

1 Answers1

0

Use a named function

var fnc = function(){
 A(); B();
};
window.setInterval(fnc,10000);
fnc();

Or use setTimeout

(function x(){ A(); B(); window.setTimeout(x, 10000);}())
epascarello
  • 204,599
  • 20
  • 195
  • 236