callbacks.has([callback]) returns a boolean (since jQuery 1.7). With a function, it asks whether that handler is on the list. With no argument, it asks whether the list has any callbacks attached.
Remember
callbacks.has(foo) // true if foo is on the list
callbacks.has(bar) // false if bar was never added
callbacks.has() // true if the list is non-empty
Keep the function reference, then ask before you add or remove.
Store handlers in named variables (not only inline anonymous functions).
add() the ones you need.
Call has(fn) for one handler, or has() for “any left?”.
Use the boolean to guard add() / remove() or to assert in tests.
Piece
Required?
Role
callback
No
Function to look up; omit = “any attached?”
Return
—
true / false (boolean)
Pseudocode
Pseudocode
function has(callbacks, callback):
if callback is provided:
return callback is in callbacks.list // reference match
else:
return callbacks.list has at least one handler
Reference
Cheat Sheet
Membership check — not fire status, not lock status.
Membership flips when you unregister the same reference.
jQuery
var onReady = function () {
console.log("ready");
};
var cbs = $.Callbacks();
cbs.add(onReady);
console.log(cbs.has(onReady)); // true
cbs.remove(onReady);
console.log(cbs.has(onReady)); // false
var handler = function (msg) {
console.log(msg);
};
var cbs = $.Callbacks();
function ensure(fn) {
if (!cbs.has(fn)) {
cbs.add(fn);
}
}
ensure(handler);
ensure(handler); // no second add
cbs.fire("once");
// once
$.Callbacks("unique") blocks duplicate adds at creation time; use has when you need an explicit guard.
Compatibility
Browser Support
callbacks.has() has shipped since jQuery 1.7 with $.Callbacks. It works in all modern browsers with jQuery loaded.
✓ jQuery 1.7+
callbacks.has()
Return true if the list has any callbacks, or if a given function is registered.
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
callbacks.has()Excellent
Bottom line: Call has(fn) for one handler, or has() to see if anyone is listening — both return a boolean.
Analysis
Performance Notes
Approach
Cost
Best for
has(fn)
O(n) scan
Lookup one handler
has()
O(1) length check
Non-empty test
Repeated guards
Cheap at small n
Plugin subscribe paths
Callbacks lists are usually short. Prefer named handlers and optional unique over complex bookkeeping.
Remember
Key Takeaways
Role: boolean membership check for Callbacks.
Two forms:has(fn) or has() for any.
Identity: keep the same function reference.
Read-only: does not add, remove, or fire.
One line:has(fn) asks “is this handler registered?” — same object you add()ed.
Frequently Asked Questions
has() returns a boolean. With no argument, it tells you whether the list currently has any callbacks. With a function argument, it tells you whether that exact function is on the list.
has() checks membership (handlers on the list). fired() checks whether fire() or fireWith() has run at least once. A list can have handlers and never be fired, or be fired and later emptied.
Yes. Pass the same function object you added. Two separately written functions with identical code are not the same — has() will return false for the second one.
Yes. Officially, omitting the callback asks whether the list has any callbacks attached (non-empty). Use has(fn) when you care about one specific handler.
No. It is a read-only check. Use add(), remove(), empty(), or fire() to change or invoke the list.
Guard duplicate add() when you cannot use the unique flag, confirm a handler before remove(), or assert in tests that a subscriber was registered.