diff --git a/src/callbacks.js b/src/callbacks.js index 51e3a3ab9..8b6a57f9f 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -151,8 +151,10 @@ jQuery.Callbacks = function( options ) { }, // Remove all callbacks from the list empty: function() { - list = []; - firingLength = 0; + if ( list ) { + list = []; + firingLength = 0; + } return this; }, // Have the list do nothing anymore diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 843c95849..d997a0d9e 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -340,3 +340,18 @@ test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", fun ok( true, "no stack overflow" ); }); + +test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function() { + + expect( 1 ); + + var cb = jQuery.Callbacks(), + fired = false, + shot = function() { fired = true; }; + + cb.disable(); + cb.empty(); + cb.add( shot ); + cb.fire(); + ok( !fired, "Disabled callback function didn't fire" ); +});