开发者

Calling setInterval from a self-executing function

开发者 https://www.devze.com 2023-02-27 09:53 出处:网络
The following way to call setInterval seems to work in Firefox 3.5 and Chromium 10.0 but not in Firefox 4.

The following way to call setInterval seems to work in Firefox 3.5 and Chromium 10.0 but not in Firefox 4.

var setInterval;
(function runmenow () {
  setInterval(function () { document.write('hello<br /&g开发者_JAVA技巧t;'); }, 1000);
}());

Firebug tells me that "setInterval is not a function". Why isn't setInterval available in this context?


This (i believe) is because you are setting setInterval as null in that first line.

just do:

//var setInterval; <--remove
(function runmenow () {
  setInterval(function () { document.write('hello<br />'); }, 1000);
}());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号