How to pass a variable to setInterval?

前端 未结 1 1000
太阳男子
太阳男子 2021-01-17 06:18

I need to update the time in my setInterval. The value is returned by the function that setInterval is executing.

read_log();

1条回答
  •  梦毁少年i
    2021-01-17 07:01

    If you need to change the repetition interval after each call to read_log(), you can't use setInterval() -- that uses a constent repetition. You need to use setTimeout, so you can change the period each time:

    function call_read_log() {
        var count = read_log();
        setTimeout(call_read_log, count);
    }
    call_read_log();
    

    0 讨论(0)
提交回复
热议问题