Skip to main content

Bug Tracker

Side navigation

#13796 closed feature (plugin)

Opened April 19, 2013 07:51PM UTC

Closed April 29, 2013 03:13PM UTC

Last modified April 30, 2013 04:13AM UTC

[Suggest] $.Callbacks as callback handler

Reported by: hugosenari@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

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();
 cb.add(cb2)

That is my suggestion.

Thanks

Attachments (0)
Change History (4)

Changed April 29, 2013 03:13PM UTC by dmethvin comment:1

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.

Changed April 30, 2013 01:36AM UTC by hugosenari@gmail.com comment:2

Hi,

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

Changed April 30, 2013 03:15AM UTC by jaubourg comment:3

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.

Changed April 30, 2013 04:13AM UTC by hugosenari@gmail.com comment:4

jaubourg,

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