Is there any difference between these 2 statements
setInterval(animateImage, 1000);
or
setInterval('animateImage()', 1000);
Will the second statement be interpreted by the browser js engine is any different way that could cause memory leak or performance issues. Same is the case with the setTimeout() call. The application makes use of 4 timer calls with 1-2 sec intervals.
The biggest difference is that the second statement will cause
animateImage()to be evaluated in global scope.This can lead to problems if
animateImageis not in global scopeanimateImagehas to access variables that are not in global scopeE.g. the following will not work:
Actually there is never a reason to use the second statement, so the question about memory leaks is not relevant anymore 😉
And obviously, passing a direct reference to a function will be ‘faster’ than
evaluating a string.