There are some caveats, but you can totally use jQuery to create events on plain objects.
When viewing the DOM in the elements panel, any element with an event bound to
it shows a little
ev icon. Hover on the item, and it shows you the functions
that handle the event. Chrome also has this feature, but its buried in another
tab on the sidebar.
The really cool thing, that even Chrome doesn’t yet have, is that it shows your code instead of just the jQuery event. In chrome, all you see is some minified jQuery source which doesn’t tell you very much. It does confirm there is an event bound, but you probably already knew that.
I got bit by this in some code that was like this:
Somehow there was some null
Foos in my
IEnumerable. When calling
RenderPartial, if the
foo local is null, it passes
Model to the partial
view rather than just a null. This is completely unexpected, and results in a
strange error about the partial view receiving an
IEnumerable<Foo> instead of
Foo. You stare at the code thinking “How in the heck did that happen!?”
I think a better result would be