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