eval - 得到名字吗?
是否可以为我使用 eval 执行的代码命名?
当浏览器加载一个文件并执行它,然后代码抛出异常时,浏览器可以告诉我在哪个文件的哪一行发生了异常。
我希望它还可以告诉我在哪里以及在哪个eval
ed代码中发生了异常。它应该显示我当时给这段代码的名称。
希望你明白我想要什么。
感谢您的帮助!
Is it possible to give a name to code that I execute using eval?
When the browser loads a file and executes it, and then the code throws an exception, the browser can tell me in which file at which line the exception happened.
I want that it also can tell me where and in which eval
ed code an exception happened. It should display the name I gave this code then.
Hope you understand what I want.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在执行 eval 之前将您的名称分配给本地变量,然后将 eval 包装在 try/catch 中。在 catch 中,您将同时拥有名称和异常。
您无法让浏览器告诉您评估代码中的哪一行包含问题,因为代码被视为一个不同的单元,但您可以记录问题代码的名称和问题代码本身,如下所示如上所述。
Assign your name to a local var right before executing the eval and then wrap the eval in a try/catch. In the catch, you'll have both the name and the exception.
You can't get the browser to tell you which line in the eval'd code contains the problem, as the code is treated as one distinct unit, but you can log both the name of the problem code and the problem code itself, as noted above.