views:

45

answers:

1
+1  Q: 

JavaScript Error

could someone give me an extra pair of eyes on this and tell me what is wrong?

Problem at line 262 character 9: Implied eval is evil. Pass a function instead of a string.

setTimeout("dojo.addClass(dojo. byId('transition'), 'hide')",1380);

+1  A: 

JavaScript is not PHP pre-5.3, and you don't pass callbacks as strings. You use an anonymous function like this:

setTimeout(function() { dojo.addClass(dojo.byId('transition'), 'hide'); }, 1380);
Reinis I.
More to the point, JavaScript *today* is not JavaScript in 1997. :-)
T.J. Crowder
Actually, `setTimeout` takes a string as the 1st param, and an int as the second. http://www.w3schools.com/js/js_timing.asp
Rocket
You actually can pass javascript code as string to `setTimeout()`. It will get `eval`'ed.
jAndy
thanks what a hit myself in the head mistake.
Moja Ra
I take back my down vote after realizing this is the correct answer, as the error told you what to do: 'Pass a function instead of a string'.
Rocket
I didn't say that you can't do it, but that it's not an accepted practice, and that's why JSLint is complaining. The downvote is unjustified.
Reinis I.
@Reinis: Sorry, you said 'you don't', so I assumed you meant that it was syntactically incorrect.
Rocket