From 245f5a244e024cb99ac84be86f86b88654a909c9 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 25 Apr 2012 16:08:38 +0200 Subject: [PATCH] Regression: makes sure that all instances of a callback are removed. Unit test added. --- src/callbacks.js | 4 ++-- test/unit/callbacks.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/callbacks.js b/src/callbacks.js index a6c504c79..bf51ad549 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -119,8 +119,8 @@ jQuery.Callbacks = function( options ) { // Remove a callback from the list remove: function() { if ( list ) { - jQuery.each( arguments, function( index, arg ) { - if ( ( index = jQuery.inArray( arg, list ) ) > -1 ) { + jQuery.each( arguments, function( _, arg, index ) { + while( ( index = jQuery.inArray( arg, list, index || 0 ) ) > -1 ) { list.splice( index, 1 ); // Handle firing indexes if ( firing ) { diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 6fca16be9..3e9936238 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -235,3 +235,18 @@ test( "jQuery.Callbacks.fireWith - arguments are copied", function() { strictEqual( hello, "hello", "arguments are copied internally" ); }); }); + +test( "jQuery.Callbacks.remove - should remove all instances", function() { + + expect( 1 ); + + var cb = jQuery.Callbacks(); + + function fn() { + ok( false, "function wasn't removed" ); + } + + cb.add( fn, fn, function() { + ok( true, "end of test" ); + }).remove( fn ).fire(); +});