]> source.dussan.org Git - jquery.git/commitdiff
Regression: makes sure that all instances of a callback are removed. Unit test added.
authorjaubourg <j@ubourg.net>
Wed, 25 Apr 2012 14:08:38 +0000 (16:08 +0200)
committerjaubourg <j@ubourg.net>
Wed, 25 Apr 2012 14:08:38 +0000 (16:08 +0200)
src/callbacks.js
test/unit/callbacks.js

index a6c504c79b12914e91cd1f90d6ab16b62ebd39db..bf51ad54924893fc6d12acb226d776502bf0334c 100644 (file)
@@ -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 ) {
index 6fca16be96007ad3835aa5401642095d41f4eb3f..3e99362383467a9f69490ededbc9427cd209417b 100644 (file)
@@ -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();
+});