开发者

Eval'd behind the scene?

开发者 https://www.devze.com 2023-04-13 02:40 出处:网络
I heard that when I\'m doing this: <a onclick=\'foo()\'></a> behind the scenes, it generates me an anonymous function, or maybe an eval\'d function...? I\'m confused, because I do h开发

I heard that when I'm doing this:

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

behind the scenes, it generates me an anonymous function, or maybe an eval'd function...? I'm confused, because I do h开发者_如何学Pythonave a function foo, so where is the extra code?

Could I please get some explanation/clarification ?


Yes, it does. It generates an anonymous function, which has body set to what you've enclosed in quotes (so it will call your foo() when executed).

It can be observed when you put a breakpoint in your function and look at the stack trace when it gets hit.

Update

Some illustations: Firebug/Firefox (more Firebug), Chrome

0

精彩评论

暂无评论...
验证码 换一张
取 消