Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- When would I use JQuery.Callbacks?
- $.callbacks.add("foo", myFunction);
- $.callbacks().fire("foo", args);
- .fireWith(context, args)
- var clickCallbacks = $.Callbacks();
- clickCallbacks.add(function() { //one one function piece
- //parse and do something on the scope of `this`
- var c = parseInt(this.text(), 10);
- this.text(c + 1);
- });
- clickCallbacks.add(function(id) { //add a second non-related function piece
- //do something with the arguments that were passed
- $('span', '#last').text(id);
- });
- $('.click').click(function() {
- var $ele = $(this).next('div').find('[id^="clickCount"]');
- clickCallbacks.fireWith($ele, [this.id]); //do two separate but related things.
- });
- readyList = jQuery.Callbacks( "once memory" );
- ready: function( fn ) {
- // Attach the listeners
- jQuery.bindReady();
- // Add the callback
- readyList.add( fn );
- return this;
- }
- readyList.fireWith( document, [ jQuery ] );
Add Comment
Please, Sign In to add comment