在JavaScript中有一个简单的方法来运行现在的函数和特定的时间间隔

There is Short way in JavaScript to run now function and in Specific interval

本文关键字:时间 函数 运行 JavaScript 有一个 简单 方法      更新时间:2023-09-26

有时候,我想在现在和将来运行一些东西。

有近路吗?

var myFunctionName = function(){
  alert('ok');
  alert('I want this to run now, and after every 100ms');
}
setInterval(a, 100);
myFunctionName();

是。任何函数都可以返回自己。然后你可以在setInterval中运行它,而不需要给它任何名字。

setInterval((function(){
alert('ok');
alert('I want this to run now, and after every 100ms')
return (arguments.callee)
})(),100)