ecometer

Use functions instead of strings as the argument of setTimeout() and setInterval()

(Development)
#26

Functions or character strings can be passed as arguments to SetTimeout() and setInterval(). In keeping with the previous best practice, using eval() and thus passing character strings is not recommended. Furthermore, if the argument passed is a string, it has to be evaluated by the interpreter before being converted into code. On the other hand, if this argument is a function or a reference to a function, no evaluation is needed, reducing CPU usage.

Instead of:

var timeoutID = setTimeout('console.log("Hello Dolly");', 1000);

write:

var aFonction = function() {
    console.log('Hello Dolly');
}
var timeoutID = setTimeout(aFonction, 1000);
This best practice should only be applied if it is coherent with your project's specifications.
Under CC-By-NX-SA license