Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to eliminate error: "Implied eval is evil"

I'm trying to make my code JavaScript "strict", so I'm running it through JSLint to ensure my code is compliant.

However, on the following code:

setTimeout("getExtJs()", 2000);

I receive the following error:

Implied eval is evil. Pass a function instead of a string.

How do I make my code JavaScript "strict"?

like image 736
HeatherK Avatar asked Dec 01 '22 09:12

HeatherK


1 Answers

setTimeout(getExtJs, 2000);

Note that there are no quotes around getExtJs, I am passing the function not a String.

EDIT: As noted in the comments the reason why JSLint is upset is that when the first argument is a String it is processed as code to be executed in the same manner as eval()

See https://developer.mozilla.org/en/window.setTimeout

To find out why eval() (and by extension using Strings as the 1st argument here) is evil see the Mozilla Developer Network entry for eval.

like image 119
Adam Avatar answered Dec 10 '22 23:12

Adam