jQuery callbacks.fireWith() Method — Context and Args
Beginner
5 min read
Updated: Oct 2026
4 examples
Live preview
Definition
What Is fireWith()?
callbacks.fireWith(context, args) runs every handler on a Callbacks list (since jQuery 1.7) with this set to context and with values from the args array. Returns the same Callbacks object for chaining.
Remember
callbacks.fireWith(window, ["foo", "bar"])
// each handler runs as: fn.call(window, "foo", "bar")
fire("a", "b") // args only
fireWith(ctx, ["a", "b"]) // this + args array
Pick a context object, pack arguments into an array, then fire.
Create a list and add() handlers that expect a useful this.
Choose the context (element, plugin instance, plain object, …).
Call fireWith(context, [arg1, arg2, …]).
Omit args when handlers need this but no parameters.
Piece
Required?
Role
context
No*
Value of this inside each handler
args
No
Array / array-like of arguments (*omit = none)
Return
—
Same Callbacks object (chainable)
Pseudocode
Pseudocode
function fireWith(callbacks, context, args):
if callbacks is disabled: return callbacks
if once and already fired: return callbacks
argList = args or []
for each handler in callbacks.list:
handler.call(context, ...argList)
mark list as fired
return callbacks
Reference
Cheat Sheet
Keep these facts handy when choosing fireWith over fire.
Optional. You may pass [] explicitly for the same effect.
Edge Cases & Pitfalls
Most bugs come from confusing fire’s rest args with fireWith’s array.
array
Second parameter is one array
Write fireWith(ctx, [a, b]), not fireWith(ctx, a, b).
arrow
Arrow functions ignore this
If you need the context, register a normal function, not an arrow — arrows keep lexical this.
disable
Disabled / once behave like fire
After disable(), fireWith is a no-op. With once, only the first call runs handlers.
null
Be careful with null context
Passing null/undefined as context follows normal Function.prototype.call rules — prefer an explicit object when handlers use this.
Compatibility
Browser Support
callbacks.fireWith() has shipped since jQuery 1.7 with $.Callbacks. It works in all modern browsers with jQuery loaded.
✓ jQuery 1.7+
callbacks.fireWith()
Invoke every handler with a chosen this context and an arguments array.
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.fireWith()Excellent
Bottom line: Call fireWith(context, [args…]) when handlers need a custom this. Use fire() when you only need to pass arguments.
Analysis
Performance Notes
Approach
Cost
Best for
fireWith(ctx, args)
O(n) handlers
Publish with custom this
fire(args…)
O(n) handlers
Args only — slightly simpler call
Heavy work in handlers
Blocks the pass
Keep callbacks light
Cost matches fire() — one call per handler. Prefer lean subscribers; defer expensive work outside the Callbacks pass.
Remember
Key Takeaways
Role: fire handlers with a chosen this and args array.
Args: always pack values into an array (or omit).
vs fire: use fire for args-only publishes.
Status: also sets fired() to true.
One line:fireWith(context, [args…]) is fire plus control over this — remember the array.
Frequently Asked Questions
fireWith(context, args) runs every handler on the Callbacks list with this set to context and with the values from the args array (or array-like object). It returns the same Callbacks object for chaining.
fire(a, b) passes arguments as separate parameters and does not let you choose this. fireWith(ctx, [a, b]) sets this to ctx and requires arguments in an array. Prefer fireWith when handlers need a DOM node, plugin instance, or other object as this.
Yes — pass an Array or array-like object as the second parameter. Omitting args (or passing undefined) means handlers receive no arguments. Do not write fireWith(ctx, "a", "b") — that is not the API.
Yes. After fireWith() runs, fired() returns true — same as after fire().
Same rules as fire(): disable() makes fireWith() a no-op; with once, only the first successful fireWith() invokes handlers.
When subscribers expect this to be your widget or element — for example fireWith(element, [eventData]) so handlers can use this.id or $(this).