The $.Callbacks() factory creates a managed list of functions you can register with add() and run with fire(). Optional flags control firing behavior. This tutorial covers syntax, all four flags, five worked examples, and how Callbacks power jQuery Deferred internally.
01
Factory
$.Callbacks()
02
once
Fire one time
03
memory
Remember args
04
unique
No duplicates
05
stopOnFalse
Break chain
06
Deferred
Internal use
Fundamentals
Introduction
JavaScript apps constantly coordinate work through callbacks — functions passed to run later when data arrives, a user clicks, or a timer finishes. Scattering those functions across nested calls gets messy fast. jQuery’s Callbacks object gives you a reusable list with a small, predictable API.
The entry point is $.Callbacks(). It returns a fresh list you configure with optional flags, populate via add(), and trigger with fire(). jQuery itself uses this machinery inside Deferred for done, fail, and related queues.
Concept
Understanding the $.Callbacks() Method
$.Callbacks([flags]) is a factory function, not a method on an existing object. Each call produces an independent callback list with methods like add, remove, fire, lock, and disable.
Without flags, the list behaves simply: every fire() invokes all registered handlers in order. Flags tweak that behavior — run only once, recall last arguments for late subscribers, skip duplicate functions, or halt when a handler returns false.
💡
Beginner Tip
Pick flags when you create the list — you cannot change them afterward. Start with no flags for learning; add "once memory" when building plugin init hooks.
Foundation
📝 Syntax
General form of the factory:
jQuery
jQuery.Callbacks( [ flags ] )
Parameters
flags (optional) — a string of space-separated behavior modifiers. Omit for default multi-fire behavior.
Available flags
Flag
Effect
once
The list fires at most one time; later fire() calls are ignored.
memory
Remembers the last fire() arguments; newly add()ed callbacks run immediately with those values.
unique
Ignores attempts to add the same function reference twice.
stopOnFalse
Stops invoking remaining callbacks when one returns false.
Returning anything other than false continues the chain. This mirrors jQuery’s event system where false can cancel default actions.
Applications
🚀 Use Cases
Custom events — expose $.Callbacks() lists as onReady, onChange, or onDestroy hooks.
Modular development — decouple publishers (fire) from subscribers (add) inside a module.
Asynchronous coordination — queue steps that run when a long task completes.
Plugin extensibility — ship a plugin with internal Callbacks lists third parties can extend.
Deferred internals — understand how jQuery queues done/fail/progress handlers under the hood.
🧠 How $.Callbacks() Works
1
Factory call
$.Callbacks(flags) returns a new list object configured with your flags.
Create
2
Register
Call add() to queue handlers. With memory, late adds may fire instantly.
add()
3
Invoke
fire() or fireWith() runs handlers, honoring once and stopOnFalse.
fire()
=
🔌
Controlled callback flow
Predictable pub/sub without reinventing event lists in every plugin.
Important
📝 Notes
Flags are fixed at creation — combine them in one string: "once memory unique".
memory without a prior fire() does nothing special on add().
unique compares function references, not logical equality.
Lists can be lock()ed or disable()d after creation — see those tutorials.
Deferred’s done queue uses Callbacks with "once memory" semantics internally.
Compatibility
Browser Support
$.Callbacks() was added in jQuery 1.7 and is available in all subsequent 1.x, 2.x, and 3.x releases wherever jQuery runs.
✓ jQuery 1.7+
jQuery $.Callbacks()
Supported in all modern browsers and legacy IE when using a compatible jQuery build. Behavior is normalized by jQuery, not the host browser.
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()Universal
Bottom line: Safe in jQuery-based projects. Pick flags at creation time for the behavior you need.
Wrap Up
🎉 Conclusion
$.Callbacks() is the factory at the heart of jQuery’s callback management. Master the default list first, then use flags — especially once and memory — for plugin-ready patterns and predictable event buses.
Explore add(), fire(), and disable() next to complete your Callbacks toolkit.
Fire huge lists on every mousemove without throttling
Skip error handling inside plugin hooks
Reimplement Deferred when Callbacks + flags suffice
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $.Callbacks()
The factory behind jQuery callback lists.
5
Core concepts
⚙01
Factory
Creates lists
API
1×02
once
Single fire
Flag
💾03
memory
Replay args
Late add
🔖04
unique
Dedupe refs
Flag
❚05
stopOnFalse
Break chain
Filter
❓ 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: once (fire only one time), memory (remember last fire arguments), unique (ignore duplicate function references), and stopOnFalse (stop the chain when a callback returns false). Combine them, e.g. $.Callbacks("once memory").
A default list runs every handler on each fire(). A once list ignores subsequent fire() calls after the first successful invocation — useful for initialization hooks.
After fire() runs, memory stores the last arguments. Any callback added later is invoked immediately with those stored values — handy when subscribers register after an event already fired.
jQuery Deferred uses Callbacks lists internally for done, fail, progress, and always queues. $.Callbacks() exposes the same list machinery directly for custom event buses and plugin APIs.
If you already use jQuery plugins or legacy jQuery code, yes. For greenfield apps without jQuery, native EventTarget, mitt, or Promise patterns often suffice — but understanding Callbacks helps when reading jQuery source and plugins.
Did you know?
jQuery’s $.ajax() done and fail queues are Callbacks lists created with "once memory" — so a handler you attach after the request completes still runs with the response data.