如何消除错误:“隐含的评估是邪恶的” [英] How to eliminate error: "Implied eval is evil"

查看:145
本文介绍了如何消除错误:“隐含的评估是邪恶的”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使我的代码JavaScript严格,所以我通过 JSLint 来运行它以确保我的代码是合规的。

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

但是,在以下代码中:

setTimeout("getExtJs()", 2000);

我收到以下错误:


隐含的评估是邪恶的。传递函数而不是字符串。

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

如何使我的代码JavaScript严格?

How do I make my code JavaScript "strict"?

推荐答案

setTimeout(getExtJs, 2000);

请注意,getExtJs周围没有引号,我传递的函数不是String。

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

编辑:
如评论中所述,JSLint令人不安的原因是,当第一个参数是String时,它将作为代码处理以与eval()相同的方式执行

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()

参见 https://developer.mozilla.org/en/window.setTimeout

找出eval()的原因(以及使用扩展程序)字符串作为第一个参数在这里是邪恶的看到 eval的Mozilla开发者网络条目

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.

这篇关于如何消除错误:“隐含的评估是邪恶的”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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