javascript JSLint“document.write 可以是 eval 的一种形式” - 这是怎么回事?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5488843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSLint "document.write can be a form of eval" - How is this so?
提问by James Wiseman
I've come across this message in JSLint...
我在 JSLint 中遇到过这条消息......
document.write can be a form of eval.
document.write 可以是 eval 的一种形式。
and was wondering exactly how so?
并想知道究竟是怎么回事?
The JSLint instructionspage states:
该JSLint的说明页状态:
The eval function...provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding....
eval 函数...提供对 JavaScript 编译器的访问。这有时是必要的,但在大多数情况下,它表明存在极其糟糕的编码......
So, how does document.write
"provide access to the JavaScript compiler" then?
那么,如何document.write
“提供对 JavaScript 编译器的访问”呢?
Thanks
谢谢
回答by Ben Voigt
What does your browser do with this?
你的浏览器用它做什么?
document.write('<script type="text/javascript">window.alert("evaled " + (1 + 2))</script>');