Eval'd behind the scene?
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
精彩评论