Why are event handler registration methods added to jQuery.attrFn[]?

Why are event handler registration methods added to jQuery.attrFn[]?

From browsing the source, I see that event handler methods like .click(), keydown(), and so on are added to the jQuery.attrFn[] array.  This means that they are specially handled by .attr(): if you try to set an attribute with the same name as one of these methods, the event-hander registration method will be called instead.

So far, so good; that sounds like a cool idea.  I ought to be able to do things like:

  1. $("p").attr({
  2.   lang:"en",
  3.   click: function() { /* handle click events */ }
  4. });

But the problem is that when attr() sees a attribute value that is a function, it invokes it, so the code above wouldn't work.

What's the deal here?  I see four possibilities:

0) I'm just confused and I'm missing something obvious.

1) Those event handling methods shouldn't be added to jQuery.attrFn[]  That is old, broken code that should be removed.

2) The .attr() method (or the internal access() or jQueyr.attr() functions it calls) are buggy and need to be modified to not invoke function values when the attribute name is the same as an event handler name.

3) Some web sites are actually relying on the fact that these methods are added to attrFn[] and they are passing functions that return function to attr(). So even though this is kind of bizarre, it can't be fixed for reasons of backward compatiblity.

Thanks for any insight!

      David