Bug Tracker

Opened 5 years ago

Closed 5 years ago

#15213 closed bug (migrated)

Calling .empty() on a disabled callbacks object re-enables it

Reported by: TheDistantSea Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.11.1
Keywords: Cc:
Blocked by: Blocking:


Earlier today I answered this StackOverflow question, wherein this behavior is shown:

var c = $.Callbacks();
var f = /* some function */;
c.disabled(); // of course true
c.fire(); // invokes f!

This behavior occurs in all versions of jQuery I tested (latest 1.9, 1.10, 1.11, 2.0, 2.1) -- here's a fiddle to easily reproduce it.

The problem is that .disable() relies on setting internal variables of the callbacks object to undefined, and while most other methods such as .add() test and this condition and abort if true, .empty() itself does not. Instead it resets some of those variables, which causes the abort test in the other methods to erroneously pass and ultimately for callbacks to be added to and invoked by a disabled object.

Change History (2)

comment:1 Changed 5 years ago by TheDistantSea

I also made a PR on GitHub: https://github.com/jquery/jquery/pull/1643

comment:2 Changed 5 years ago by m_gol

Resolution: migrated
Status: newclosed
Note: See TracTickets for help on using tickets.