JavaScript Mac Firefox setInterval() Wierdness
I first encountered a problem with safari, where set interval would behave unpredicatbly when the function name was not enclosed within quotations (and optionally it seams with added parentheses):
repeatInterval = setInterval("foo()", 50);
Upon changing my code to rea开发者_JAVA技巧d in this way, it seams it does not get executed at all in the Mac version of Firefox.
I did some further testing an ensured that it works completely fine under linux and windows versions (including both 3.0.10 and 3.6 under windows). The only combination that throws up this problem is Firefox (3.6 in this case) on Mac OS X Snow Leopard.
It dose not work at all unless written in the following format:
repeatInterval = setInterval(foo, 50);
Is there a sollution to this problem that will work in all other browsers and Firefox on the Mac, without testing for the operating system and browser in the javascript and hacking it to work accordingly?
Don't pass a string as the first parameter of setInterval
or setTimeout
. You should either pass a function identifier (as you did with setInterval(foo, 50);
) or pass an anonymous function (using the function
keyword).
精彩评论