The has() method checks whether a specific function reference is already registered on a Callbacks list. This tutorial covers syntax, five examples, how it compares with add() and remove(), and patterns for avoiding duplicate subscriptions.
01
Syntax
has(callback)
02
Boolean
true / false
03
Reference
Same function object
04
vs add()
Check before add
05
vs fired()
Different question
06
Dedup
Skip duplicates
Fundamentals
Introduction
You use add() to register handlers and fire() to run them. But what if the same handler gets added twice by mistake — or you need to know whether a subscriber is already on the list before calling remove()?
has() answers that membership question. Pass the function reference you care about; jQuery returns true if that exact function is currently stored in the list.
Concept
Understanding the has() Method
callbacks.has(callback) performs a lookup by reference equality. It returns true only when the same function object you pass was previously added with add() and has not been removed with remove() or cleared with empty().
It does not accept flags, does not tell you whether the list is empty, and does not track whether fire() has run. The old reference incorrectly documented has(flags) and has() with no arguments — neither matches jQuery’s actual API.
💡
Beginner Tip
Store your handler in a named variable first. has() needs that same variable reference — not a freshly created anonymous function with identical code.
Foundation
📝 Syntax
General form of callbacks.has:
jQuery
callbacks.has( callback )
Parameters
callback — The function reference to look up in the list.
Return value
true if the callback is registered; false otherwise.
Basic pattern
jQuery
const callbacks = $.Callbacks();
function onReady() {
console.log("Ready!");
}
callbacks.add(onReady);
console.log(callbacks.has(onReady)); // true
function otherHandler() {}
console.log(callbacks.has(otherHandler)); // false
Cheat Sheet
⚡ Quick Reference
Goal
Code
Check if handler is registered
callbacks.has(fn)
Add only if missing
if (!callbacks.has(fn)) callbacks.add(fn)
After remove()
has(fn) → false
Register handler
callbacks.add(fn)
List ever fired?
callbacks.fired()
Compare
📋 has() vs add() vs fired()
Membership check versus registration versus invocation status.
has(fn)
boolean
Is this function on the list?
add(fn)
register
Put a handler on the list
fired()
boolean
Has fire() ever run?
Side effect
none
has() is read-only
Hands-On
Examples Gallery
Each example shows a different way to use the boolean from has().
📚 Getting Started
Check membership for a known function reference.
Example 1 — Registered vs Unregistered Handler
Add one handler, then test has() with that reference and a different function.
Always keep a stable reference to handlers you may need to check, remove, or deduplicate later.
Applications
🚀 Use Cases
Duplicate prevention — guard add() when the same handler might register twice.
Safe unsubscribe — verify membership before calling remove().
Plugin APIs — expose isSubscribed(fn) backed by has(fn).
Unit tests — assert a mock handler was registered on a Callbacks list.
Conditional wiring — attach optional listeners only when not already present.
🧠 How has() Looks Up Handlers
1
Pass callback
Supply the function reference you want to find.
Input
2
List scan
jQuery compares by reference against registered handlers.
Lookup
3
Return boolean
true if found; false if not. No list mutation.
Result
=
✅
Confident membership
You know whether a specific handler is on the list before you act.
Important
📝 Notes
has() requires a callback argument — it does not accept flags.
Matching is by reference, not by function source code or name.
Adding the same reference twice makes has() true, but fire() will run it twice.
has() is unrelated to fired() (invocation history) and disabled() (shutdown status).
After empty(), every previous handler returns false from has().
Compatibility
Browser Support
callbacks.has() is part of jQuery’s Callbacks API since jQuery 1.7 and works wherever jQuery runs.
✓ jQuery 1.7+
jQuery Callbacks.has()
Supported in jQuery 1.x, 2.x, and 3.x. Reference lookup behaves consistently across browsers.
100%With jQuery loaded
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()Universal
Bottom line: Safe in jQuery projects. Pass the exact function reference you added with add().
Wrap Up
🎉 Conclusion
The callbacks.has() method tells you whether a specific function reference is registered on a Callbacks list. It is read-only, returns a boolean, and pairs naturally with add() and remove() for membership-aware code.
Next, learn lock() to freeze the list so no new handlers can be added — while still allowing fire().
Store handlers in named variables for has() lookups
Guard add() with if (!has(fn))
Use has() before remove() when unsure
Expose membership checks in plugin subscribe APIs
Test registration with has(mockFn)
❌ Don’t
Pass flags to has() — unsupported
Call has() with no argument expecting “list empty”
Confuse has() with fired()
Expect lookalike functions to match by code
Rely on has() after losing the original reference
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about has()
Membership checks for Callbacks lists.
5
Core concepts
?01
has(fn)
Membership query
API
T/F02
Boolean
Registered?
Return
🔗03
Reference
Same object
Match
+04
add()
Register fn
Pair
▶05
fired()
Different check
Compare
❓ Frequently Asked Questions
has(callback) checks whether a specific function reference is currently registered on the Callbacks list. It returns true if that exact function was added and not yet removed, otherwise false.
No. Unlike incorrect documentation sometimes found online, has() takes a callback function — not flags. Flags belong on $.Callbacks("once memory") at creation time.
has(fn) asks "is this function on the list?" fired() asks "has the list been invoked at least once?" They answer completely different questions.
Only if you keep a reference to the same function object. has() uses reference equality — two separately declared functions with identical code are not considered the same.
No meaningful membership check occurs without passing the function you want to look up. Always pass the callback reference: callbacks.has(myHandler).
Common uses: prevent duplicate add() of the same handler, guard remove() when unsure of membership, and write tests that assert a subscriber was registered.
Did you know?
jQuery Callbacks does not prevent duplicate registrations. If you call add(sameFn) twice, has(sameFn) is true — but the next fire() invokes that function twice. A has() guard before add() is the standard fix.