Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13796 closed feature (plugin)

[Suggest] $.Callbacks as callback handler

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


Maybe makes sense, send 'Callbacks Object' to parameters that receive a function as callback.

 var cb = $.Callbacks();
 $('a:first').on('click', cb);

And probably I can do this too:

var cb = $.Callbacks(),
 cb2 = $.Callbacks();

That is my suggestion.


Change History (4)

comment:1 Changed 10 years ago by dmethvin

Resolution: plugin
Status: newclosed

You could certainly make a plugin to do this, but it doesn't seem all that necessary in core and would add more complexity to the signature for .on() which is already pretty hairy.

comment:2 Changed 10 years ago by [email protected]


I open this ticket thinking that jQuery.events use jQuery.Callbacks, since both has a common 'interface' (add cb, remove cb, apply cb).

Looking at .on() code, I can see why you afraid to increase the signature complexity.

But my suggestion can be resolved making jQuery.Callbacks act like a function (adding call and apply methods) or returning a function object (https://github.com/hugosenari/jquery/commit/1ad3f8e905f2f240590026335e893e1719dfe516#diff-0).

Anyway I'm agree that can be done with plugin.

Thanks. Hugo

comment:3 Changed 10 years ago by jaubourg

Well, you can already do this :

  var cb = $.Callbacks();

  $( "a:first" ).on( "click", cb.fire );

So I don't see much gain in the proposal.

Remember that Callbacks and Deferred methods are "detachable" (lexically bound) so you can pass them around as needed.

comment:4 Changed 10 years ago by [email protected]


Thanks that was a good example how to do it. Clear and simple.

Note: See TracTickets for help on using tickets.