jQuery callbacks.lock() Method — Freeze List State
Beginner
5 min read
Updated: Oct 2026
4 examples
Live preview
Definition
What Is lock()?
callbacks.lock() locks a Callbacks list in its current state (since jQuery 1.7). After that, further fire() / fireWith() calls do not invoke handlers with new values. Returns the same Callbacks object for chaining.
Remember
callbacks.add(foo)
callbacks.fire("hello") // runs
callbacks.lock()
callbacks.fire("world") // ignored — list is locked
locked() → true after lock()
Fire (or set memory), then lock when the state should stop changing.
Create a list — use "memory" if late adds should still see the last fire.
add() handlers and fire() as needed.
Call lock() when values / state are final.
Check with locked(); expect later fire() to be ignored.
Piece
Required?
Role
Arguments
—
None
Return
—
Same Callbacks object (chainable)
Status
—
locked() becomes true
Pseudocode
Pseudocode
function lock(callbacks):
mark callbacks as locked
// without memory: further useful firing stops
// with memory: late add() may still run with last args
return callbacks
After lock, new fire values stay ignored; late adds still get the last args.
jQuery
var lines = [];
var foo = function (value) {
lines.push("foo: " + value);
};
var bar = function (value) {
lines.push("bar: " + value);
};
var cbs = $.Callbacks("memory");
cbs.add(foo);
cbs.fire("hello");
cbs.lock();
cbs.fire("world"); // ignored
cbs.add(bar);
cbs.fire("silentArgument"); // late add runs with "hello"
console.log(lines.join("\n"));
// foo: hello
// bar: hello
callbacks.lock() has shipped since jQuery 1.7 with $.Callbacks. It works in all modern browsers with jQuery loaded.
✓ jQuery 1.7+
callbacks.lock()
Freeze a Callbacks list so later fire() calls with new values are ignored.
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.lock()Excellent
Bottom line: Call lock() when the list state is final. Pair with memory if late subscribers should still see the last value.
Analysis
Performance Notes
Approach
Cost
Best for
lock()
O(1) flag
Freeze publish state
fire() after lock
Early exit
Safe no-op
memory + late add
O(1) per add
One-shot results + late joiners
Locking is cheap. Prefer clear lifecycle (fire → lock) over ad-hoc flags outside Callbacks when this model fits.
Remember
Key Takeaways
Role: freeze the list in its current state.
Fires: later fire() values are ignored.
memory: late add() can still get last args.
Status: read with locked().
One line:lock() freezes state — new fires stop; with memory, late adds can still see the last value.
Frequently Asked Questions
lock() freezes a Callbacks list in its current state. After lock(), further fire() / fireWith() calls with new arguments do not run handlers. It returns the same Callbacks object for chaining.
Both stop new fires from invoking handlers. With the memory flag, lock() still lets you add late handlers that receive the last memorized fire values. disable() shuts the list down more completely — “do anything more” is off.
No. Call lock() with no arguments. Flags such as memory belong on $.Callbacks("memory") when you create the list.
Officially: if the list was created with memory, additional functions may still be added after lock() and will run with the memorized last arguments — even though new fire values are ignored.
Call locked() — it returns true after lock(). That is the status check; lock() is the action.
When the publish values are final (especially with memory for late subscribers), or you want to freeze further state changes after a one-shot workflow without treating it exactly like disable().