LoginSignup
2
3

More than 5 years have passed since last update.

setInterval、setTimeOut は function をそのまま渡せる。

Posted at

setIntervalでぐぐると多くの例が関数呼び出しをわざわざ文字列にして渡しているが、普通に関数を渡せる。しかも文字列だとevalしないといけないからパフォーマンス上もよくない。何でこの風習が広がっているか謎。多分、ググルと上の方にあるからだろう。

setInterval('doSomethingPeriodically()', 1000);
setTimeOut('doSomethingAfterFiveSeconds()', 5000);
setInterval(doSomethingPeriodically, 1000);
setTimeOut(doSomethingAfterFiveSeconds, 5000);

JavaScript Performance Best Practices - Nokia Developer Wiki

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3