最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why do people say that javascript eval() is evil but you get no objections against setTimeout and setInterval etc? - Stack Overf

programmeradmin1浏览0评论

if I am not mistaken eval executes valid code in a given string

eval("alert('hey')");

and

setTimeout("alert('hey')",1000);

does just about the same thing, only with a timer. is set timeout just as risky as eval?

if I am not mistaken eval executes valid code in a given string

eval("alert('hey')");

and

setTimeout("alert('hey')",1000);

does just about the same thing, only with a timer. is set timeout just as risky as eval?

Share Improve this question edited Jun 22, 2011 at 16:31 demongolem 9,70836 gold badges97 silver badges105 bronze badges asked Aug 16, 2010 at 9:39 Abdullah KhanAbdullah Khan 2,4153 gold badges23 silver badges34 bronze badges 1
  • 3 Good question :) And I guess the answer is yes More here stackoverflow.com/questions/197769/… – mplungjan Commented Aug 16, 2010 at 9:41
Add a comment  | 

2 Answers 2

Reset to default 20

I'd say you hear the same objections. setTimeout (with string and not function parameters) is pretty much the same as eval.

If possible,

 setTimeout(function(){ alert ("hey") ; }, 1000);

Because when people say "eval", they mean "eval and any function that is more or less equivalent to eval", but the former is much shorter to say. So the answer to your question is yes, it is as risky.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论