人们为什么说javascript eval()是邪恶的,但是您对setTimeout和setInterval等没有异议? [英] Why do people say that javascript eval() is evil but you get no objections against setTimeout and setInterval etc?

查看:68
本文介绍了人们为什么说javascript eval()是邪恶的,但是您对setTimeout和setInterval等没有异议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我没记错的话,eval在给定的字符串中执行有效的代码

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

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

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

只是使用计时器,几乎可以做同样的事情.设置超时与评估风险一样高吗?

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

推荐答案

我会说您听到相同的异议. setTimeout(带有字符串而不是函数参数)与eval几乎相同.

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

如果可能,

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

这篇关于人们为什么说javascript eval()是邪恶的,但是您对setTimeout和setInterval等没有异议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆