$.Callbacks() (alias jQuery.Callbacks()) is a factory that creates a callback list — since jQuery 1.7. The list manages handlers with add(), remove(), fire(), and more. Optional flags change how the list behaves. jQuery uses the same machinery inside $.ajax() and Deferred.
Remember
var cbs = $.Callbacks() // default (multi-fire)
var cbs = $.Callbacks("once") // fire once
var cbs = $.Callbacks("memory") // replay last args on late add
var cbs = $.Callbacks("unique") // no duplicate refs
var cbs = $.Callbacks("stopOnFalse") // halt when fn returns false
var cbs = $.Callbacks("once memory") // combine flags (Deferred-style)
cbs.add(fn) → queue
cbs.fire(args…) → run handlers
Pick flags up front, create the list, then register and fire.
Decide behavior: default multi-fire, or flags like once / memory.
Call $.Callbacks() or $.Callbacks("once memory").
Register with add(), trigger with fire() / fireWith().
Clean up with remove(), empty(), lock(), or disable() as needed.
Piece
Required?
Role
flags string
Optional
Space-separated behavior modifiers
Return value
—
Callbacks object (add, fire, …)
Since
—
jQuery 1.7
Pseudocode
Pseudocode
list = empty queue
flags = parse space-separated string
memoryArgs = none
fired = false
add(fn):
if unique and fn already in list: skip
append fn
if memory and fired: call fn(memoryArgs) now
fire(args…):
if once and fired: return
fired = true
if memory: memoryArgs = args
for each fn in list:
result = fn(args…)
if stopOnFalse and result === false: break
Reference
Cheat Sheet
Flags and the methods you use most often.
Topic
Detail
Syntax
$.Callbacks( [flags] )
once
Only the first fire() runs
memory
Late add() gets last fire args immediately
unique
Same function reference added only once
stopOnFalse
Returning false stops remaining handlers
Combine
"once memory", "unique memory", …
Deferred tip
.done() / .fail() use "once memory"
Try it
Live Preview
Pick a flag mode and run a short add / fire sequence against a fresh list.
Browser demo of $.Callbacks flags — same ideas as the examples below.
Create.$.Callbacks() starts an empty multi-fire list.
First fire. Only handler 1 exists → one log line.
Second add. Handler 2 joins the same list.
Second fire. Both handlers run — the first is not cleared.
Example 2 — The once Flag
After the first fire(), later fires are ignored.
jQuery
var callbacks = $.Callbacks("once");
callbacks.add(function () {
console.log("Runs on first fire only");
});
callbacks.fire();
callbacks.fire(); // ignored
Use case. Validation pipelines where a failed check cancels the rest.
Edge Cases & Pitfalls
Check these before choosing flags for a real list.
flags
Flags are immutable
Set them only in $.Callbacks(flags). Wrong flags? Create a new list.
default
Default lists re-fire everyone
A second fire() runs all current handlers again — use once if that is wrong for your case.
unique
unique is by reference
Two anonymous functions with identical bodies are still different objects — both get added.
memory
Empty fire still sets memory
Firing with no handlers still stores args when memory is on — late adds will run with those args.
stop
Only strict false stops
stopOnFalse reacts to return false. Returning 0, null, or undefined does not stop the chain.
Compatibility
Browser Support
$.Callbacks() is part of jQuery core (since 1.7). It works in any browser where your jQuery build runs — the list logic lives in jQuery, not as a separate browser API.
✓ jQuery 1.7+ · Browsers
jQuery $.Callbacks()
Supported in jQuery 1.x, 2.x, and 3.x across Chrome, Firefox, Safari, Edge, and other browsers with jQuery loaded.
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()Browsers
Bottom line: Safe wherever jQuery is loaded. Choose flags at creation, then use add() / fire() for the lifecycle.
Analysis
Performance Notes
Operation
Cost
Best for
$.Callbacks()
O(1) setup
Creating a list once per hook
add / fire
O(1) / O(n)
Register vs invoke all handlers
unique add
O(n) scan
Preventing duplicate refs
Creating a Callbacks object is cheap. Cost shows up when you fire() many heavy handlers. Keep callbacks light, prefer named refs for remove(), and avoid recreating lists on every event.
Remember
Key Takeaways
Factory:$.Callbacks() builds a managed handler list.
Flags:once, memory, unique, stopOnFalse — set at creation only.
Lifecycle:add to subscribe, fire to publish.
Deferred link: done/fail queues use "once memory" under the hood.
One line: pick flags first, then add / fire — that is the whole Callbacks model.
Frequently Asked Questions
$.Callbacks() (same as jQuery.Callbacks()) is a factory that creates a callback list — an object with add(), remove(), fire(), and related methods. Use it to manage groups of functions that should run together when an event or async step completes.
Optional space-separated strings passed at creation: once (fire only one time), memory (remember last fire args and replay them for late add()), unique (ignore duplicate function references), and stopOnFalse (stop the chain when a callback returns false). Combine them, e.g. $.Callbacks("once memory").
No. Flags are set only in the $.Callbacks(flags) call. Create a new list if you need different behavior.
After fire() runs, memory stores the last arguments. Any callback added later is invoked immediately with those stored values — the same idea Deferred uses for .done() handlers registered after resolve.
jQuery Deferred uses Callbacks lists internally for done, fail, and progress queues — typically with "once memory". $.Callbacks() exposes that same list machinery for custom hooks and plugin APIs.
Yes if you already ship jQuery plugins or need a small pub/sub inside a jQuery codebase. For greenfield apps without jQuery, native EventTarget or Promises often suffice — but Callbacks is still useful for reading jQuery internals.