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 have 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