javascript计时器事件

Ahm*_*kol 0 html javascript

我在我的程序开始时使用setInterval函数,但我的问题是我不想等到启动代码时.我希望它在应用此时间间隔后立即启动.这是我的代码:

    function initialize() {
setInterval(function(){myFunc()},5000);
}
google.setOnLoadCallback(initialize);
Run Code Online (Sandbox Code Playgroud)

bug*_*s94 5

myfunc()在加载DOM之后调用

function initialize() {
    myFunc();//it will run without waiting for 5 seconds
    setInterval(myFunc,5000);
}
google.setOnLoadCallback(initialize);
Run Code Online (Sandbox Code Playgroud)