javascript eval方法 [英] javascript eval method

查看:115
本文介绍了javascript eval方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在javascript eval()方法内观察变量值?在eval方法中是否可以进入和逐步执行?例如,使用如下代码:

How can I watch variable values inside of javascript eval() method? And is it possible to "step into" and "step over" in eval method? For example, with a code like this:

eval("if (true) { var a = 10; a += 20; alert(a); }");

我对IE9的调试更感兴趣,但我也想听听一般原则。 / p>

I am more interested in debugging in IE9, but I would like to hear general principle as well.

推荐答案

你不能在eval方法里面。你给它的代码不是代码,而是字符串。在eval()之后,它成为代码,你可以检查它。这也取决于你用来调试脚本的工具。在Chrome中,如果您单击暂停异常,并执行您的eval。它会中断(因为b是未定义的),并跳转到您可以跳过,进出的评估代码。您还可以使用 new Function(code goes here)()来评估代码

you can't inside the eval method. the code you give it is no code but a string. after the eval() then it becomes code and you can inspect it. This also depends on what tools you use to debug your script. In Chrome if you click Pause on exception, and execute your eval. it will break (because b is undefined) and jump in the evaluated code where you can step over, in and out. you can also use new Function("code goes here")() to evaluate code

这篇关于javascript eval方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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