Eval'd behind the scene?

Eval'd behind the scene?

本文关键字:the scene behind Eval      更新时间:2023-09-26

我听说当我这样做的时候:

<a onclick='foo()'></a>

在幕后,它生成了一个匿名函数,或者可能是一个eval函数…?我很困惑,因为我有一个函数foo,那么额外的代码在哪里?

我可以得到一些解释/澄清吗?

是的。它生成一个匿名函数,该函数的主体设置为您在引号中包含的内容(因此它将在执行时调用您的foo())。

当你在函数中放置一个断点,并在它被击中时查看堆栈跟踪时,可以观察到它。

一些例子:Firebug/Firefox(更多Firebug), Chrome