Pass parameters in setInterval function
Please advise how to pass parameters into a function called using setInterval
.
My example setInterval(funca(10,3), 500);
is incorrect.
Solution 1:
You need to create an anonymous function so the actual function isn't executed right away.
setInterval( function() { funca(10,3); }, 500 );
Solution 2:
now with ES5, bind method Function prototype :
setInterval(funca.bind(null,10,3),500);
Reference here
Solution 3:
Add them as parameters to setInterval:
setInterval(funca, 500, 10, 3);
The syntax in your question uses eval, which is not recommended practice.