Skip to main content

Bug Tracker

Side navigation

#5834 closed bug (fixed)

Opened January 16, 2010 06:36AM UTC

Closed January 25, 2010 10:02PM UTC

event.special namespacing bug

Reported by: cowboy Owned by:
Priority: major Milestone: 1.4.1
Component: event Version: 1.4
Keywords: Cc:
Blocked by: Blocking:

Perhaps I'm missing something, but an jQuery.event.special add method returns a function, namespacing no longer works.

This image represents what "should" work, but notice that namespacing seems to have no effect when triggering or unbinding:

If add doesn't return a function, namespacing seems to work.. but of course the event object is no longer being augmented:

Here is the code I used to test all this:

console.log( $.fn.jquery );
var i = 0;

jQuery.event.special.myevent = {
  setup: function(){
    console.log( 'setup', this.tagName, [] arguments ) );
  teardown: function(){
    console.log( 'teardown', this.tagName, [] arguments ) );
  add: function( handler, data, namespaces ){
    console.log( 'add', this.tagName, [] arguments ) );
    return function(e){ = data; = ++i;
      handler.apply( this, arguments );
  remove: function(){
    console.log( 'remove', this.tagName, [] arguments ) );

function a(e){ console.log( 'a',, ); }
function b(e){ console.log( 'b',, ); }
function bc(e){ console.log( 'bc',, ); }

var elem = $('body');

elem.bind( 'myevent.a', {x:1}, a);
elem.trigger( 'myevent' );
elem.trigger( 'myevent.a' );
elem.bind( 'myevent.b', {y:2}, b);
elem.trigger( 'myevent' );
elem.trigger( 'myevent.b' );
elem.bind( 'myevent.b.c', {z:3}, bc);
elem.trigger( 'myevent' );
elem.trigger( 'myevent.b' );
elem.trigger( 'myevent.b.c' );
elem.unbind( 'myevent.a' );
elem.trigger( 'myevent' );
elem.unbind( 'myevent', b );
elem.trigger( 'myevent' );
elem.unbind( 'myevent.b.c' );
elem.trigger( 'myevent' );

On a separate but related note, when the add "function return" is used to augment the event object, is there any way to automatically propagate It feels like an unnecessary "extra" step to me.

Attachments (0)
Change History (2)

Changed January 16, 2010 06:40AM UTC by cowboy comment:1

And in case this is reviewed by someone who isn't super familiar with jQuery.event.special, I've been working on an article explaining a bit about how Special Events work. This screenshot may help explain what the expected behavior of the setup, teardown, add and remove methods should be:

(*please* correct me if I've made any mistakes!)

Changed January 25, 2010 10:02PM UTC by john comment:2

component: unfilledevent
resolution: → fixed
status: newclosed

Both points fixed - you no longer have to copy over data anymore.