Skip to content

Commit bc1cb12

Browse files
committedDec 8, 2014
Callbacks: Disabling a callback should prevent firing
Thanks to @TheDistantSea for the report! Fixes gh-1790 Closes gh-1643
1 parent 906caeb commit bc1cb12

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎src/callbacks.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ jQuery.Callbacks = function( options ) {
151151
},
152152
// Remove all callbacks from the list
153153
empty: function() {
154-
list = [];
155-
firingLength = 0;
154+
if ( list ) {
155+
list = [];
156+
firingLength = 0;
157+
}
156158
return this;
157159
},
158160
// Have the list do nothing anymore

‎test/unit/callbacks.js

+15
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,18 @@ test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", fun
340340

341341
ok( true, "no stack overflow" );
342342
});
343+
344+
test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function() {
345+
346+
expect( 1 );
347+
348+
var cb = jQuery.Callbacks(),
349+
fired = false,
350+
shot = function() { fired = true; };
351+
352+
cb.disable();
353+
cb.empty();
354+
cb.add( shot );
355+
cb.fire();
356+
ok( !fired, "Disabled callback function didn't fire" );
357+
});

0 commit comments

Comments
 (0)