KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
We all know that passing a string to setTimeout (or setInterval ) is evil, because it is run in the global scope, has performance issues, is potentially insecure if you're injecting any parameters, etc. So doing this is definitely deprecated: setTimeout('doSomething(someVar)', 10000); in favour of this: setTimeout(function() { doSomething(someVar); }, 10000); My question is: can there ever be a reason to do the former? Is it ever preferable? If it isn't, why is it even allowed? The only scenario I've thought of is of wanting to use a function or variable that exists in the global scope but has been overridden in the local scope. That sounds to me like poor code design, however...
Tags (comma-separated)
Save Edits
Cancel