deferred.rejectWith(context [, args]) settles a Deferred as rejected (since jQuery 1.5) and runs fail callbacks with this set to context. Optional args is an array whose values become the callback parameters. It returns the same Deferred for chaining.
Remember
deferred.rejectWith(context [, argsArray])
context → this inside fail callbacks
args → array → separate parameters
reject("msg")
rejectWith(obj, ["msg"]) // same args, custom this
pair with: resolveWith / notifyWith
keep private; return promise()
Pick a context object, wrap failure values in an array, then reject.
Create a Deferred (keep it private in your helper).
Attach fail() handlers that use this if needed.
On failure, call rejectWith(context, [arg1, arg2, …]).
Return promise() to callers so they cannot settle the Deferred.
Piece
Required?
Role
context
Yes
Becomes this in fail callbacks
args
Optional
Array of values passed as parameters
Return
—
Same Deferred (chainable)
Since
—
jQuery 1.5
Pseudocode
Pseudocode
rejectWith(context, argsArray):
if already settled: return
state = "rejected"
remember context + argsArray
for each fail handler (add order):
call handler with this = context
and parameters = values from argsArray
reject(a, b) ≈ rejectWith(defaultThis, [a, b])
// difference: you choose context with rejectWith
Reference
Cheat Sheet
Keep these facts handy when failing with a custom this.
Topic
Detail
Syntax
deferred.rejectWith(context [, args])
args shape
Array → spread as callback parameters
Triggers
fail(), rejection branch of then(), always()
vs reject()
Same settle; rejectWith sets this
Family
resolveWith, notifyWith
Once
Settles once; later settle calls ignored
Since
jQuery 1.5
Try it
Live Preview
See how rejectWith() sets this and spreads an args array.
Browser demo of deferred.rejectWith — same idea as the examples below.
Result
this.id → uploader
reason → timeout
/* context becomes this in fail() */
Code
jQuery Examples
Short, copy-ready snippets. Open the browser console, or use Try It Yourself for a live editor.
Example 1 — Custom this in fail()
Pass a context object so the fail handler can read this.id.
Check these before using rejectWith() in real projects.
array
Second argument must be an array
Write rejectWith(ctx, ["msg"]), not rejectWith(ctx, "msg"). A bare string is not spread as one parameter the way you might expect.
arrow
Arrow functions ignore this
Arrow fail handlers do not get the rejectWith context. Use a normal function when you need this.
once
Settles only once
After resolve/reject/*With, further settle calls are ignored.
owner
Keep settle methods private
Return promise() so callers can attach fail but cannot call rejectWith.
Compatibility
Browser Support
deferred.rejectWith() needs jQuery 1.5+ loaded. It works across jQuery 1.5–3.x alongside reject(), resolveWith(), and notifyWith().
✓ jQuery 1.5+
deferred.rejectWith()
Works in Chrome, Firefox, Safari, and Edge when jQuery 1.5+ is loaded. Use it when fail handlers need a specific this.
100%With jQuery 1.5+
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
rejectWith()Universal
Bottom line: Safe wherever jQuery Deferreds exist. Prefer reject() when you do not need a custom this.
Analysis
Performance Notes
Approach
Cost
Best for
reject(args…)
Slightly simpler
No custom this
rejectWith(ctx, arr)
Same order of cost
Method-style fail handlers
Huge args arrays
Copied to handlers
Keep payloads small
Prefer rejectWith for correct this binding, not for speed. The expensive part is usually your fail handlers, not the settle call.
Remember
Key Takeaways
Role: reject with a chosen this and an args array.
Args: second parameter is an array that spreads to fail handlers.
Family: matches resolveWith / notifyWith.
Safety: owner-only; expose promise() to callers.
One line:rejectWith(ctx, [args…]) fails the Deferred and binds this for fail handlers.
Frequently Asked Questions
rejectWith(context, args) settles the Deferred as rejected. Fail callbacks from fail() or then() run with this set to context, and parameters taken from the optional args array.
reject(...values) passes arguments directly. rejectWith(ctx, [a, b]) lets you choose this and wrap values in an array — the same pattern as resolveWith() and notifyWith().
An optional array (or array-like) such as ["timeout"] or [404, "Not found"]. jQuery spreads those values as separate parameters to each fail callback.
When fail handlers are methods on a widget or service object and need this to point at that object — especially inside timers or nested callbacks where this would otherwise be lost.
No. A Deferred settles once. After resolve(), later rejectWith() is ignored.
Usually no. Keep the Deferred private and return promise() so outside code can listen with fail/done but cannot settle the operation.