[thelist] setInterval arguments (for IE6)

Andrew Clover and-evolt at doxdesk.com
Mon Jul 5 01:27:50 CDT 2004


Andreas Wahlin <Andreas.Wahlin at ufl.gu.se> wrote:

> I tried

> window.setInterval([...function...], 500, 'hello world');

> in IE the argument wasn't passed.

Indeed, the extended with-parameters form of setTimeout/setInterval is 
not globally supported, unfortunately.

> window.setInterval("external(\""+hello world+"\")", 500);

> This is ugly and clumsy and I hate it

Quite right. Most people use this kind of solution but it is very nasty.

> anyone with a better suggestion??

JavaScript can do closures. So this:

   function greet(greetee) {
     var greeting= 'Hello '+greetee;
     var f= function() { alert(greeting) };
     setInterval(f, 5000);
   }
   greet('world');

will work. When you define a function from inside another function, the 
  variables in the outer function scope are kept and are accessible to 
the inner function. (In the above case, the local variable 'greeting', 
as well as 'greetee' and 'f' for that matter.)

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/


More information about the thelist mailing list