Pass parameters in setInterval function

Rakesh picture Rakesh · Jan 19, 2009 · Viewed 234.3k times · Source

Please advise how to pass parameters into a function called using setInterval.

My example setInterval(funca(10,3), 500); is incorrect.

Answer

tvanfosson picture tvanfosson · Jan 19, 2009

You need to create an anonymous function so the actual function isn't executed right away.

setInterval( function() { funca(10,3); }, 500 );