Get updates

Scott Event Handler Naming Conflict with jQuery

I’m trying out Spine (and CoffeeScript) and encountered a problem setting up event handlers with my controller. Turned out to be caused by my choice of an event handler name.

In my controller I opted for the delegation shortcut, almost straight out of the Spine Controller docs:

  'click .tab': 'click'

click: (event) ->

This delegates click events on @el with the .tab selector to the ‘click’ handler method. jQuery (1.7.1) seems to get confused by this and throws an error during event dispatch (when click is triggered: “TypeError: ‘jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler ) .apply’ is not a function”)

The solution? Rename the handler to avoid conflict:

  'click .tab': 'clickHandler'

clickHandler: (event) ->

Leave a Reply