The resolveWith() method settles a Deferred as successful like resolve(), but lets you set this inside done() callbacks and pass arguments as an array. This tutorial covers syntax, five examples, comparisons with resolve() and rejectWith(), and when custom context matters.
01
Syntax
resolveWith(ctx, args)
02
context
Sets this
03
args
Array of values
04
done()
Receives results
05
vs resolve
Context control
06
Since 1.7
With Deferred API
Fundamentals
Introduction
Success handlers often need to update a specific UI widget, dashboard view, or data service. Inside a plain done() callback, this may not point where you expect — especially after setTimeout, AJAX callbacks, or nested functions. resolveWith(context, args) solves that by binding this to your chosen object when the Deferred settles as resolved.
It completes the With family: resolveWith() for success, rejectWith() for failure, and notifyWith() for interim progress — all with the same context-and-array pattern.
Concept
Understanding the resolveWith() Method
resolveWith() is part of jQuery’s Deferred Object API (since jQuery 1.7). Calling deferred.resolveWith(context, args) locks the Deferred in the resolved state and invokes every done(), then(), and success branch of always() handler with this set to context and parameters taken from the args array.
Unlike resolve(), which passes values directly with default this binding, resolveWith() gives you explicit control over both the callback context and how multiple arguments are delivered.
💡
Beginner Tip
Register done() before calling resolveWith() so the flow is easy to follow. The old reference called resolveWith() before attaching done() — that still works in jQuery, but attaching handlers first makes tutorials clearer.
Foundation
📝 Syntax
General form of deferred.resolveWith:
jQuery
deferred.resolveWith( context, args )
Parameters
context — object used as this when each done() callback runs.
args — array or array-like object whose values are passed as separate arguments to success handlers (e.g. ["Saved"] or [200, data, meta]).
Return value
Returns the same Deferred object (already settled as resolved).
Wrap multiple values in the second argument array. jQuery spreads them into your callback — same pattern as resolve(200, data, meta) but with controlled this.
Example 5 — Resolve from an Async Callback with Context
After progress updates, finish with resolveWith() inside setTimeout using an explicit service object.
jQuery sets this = context, spreads args, and locks state to resolved.
Settle
3
Handlers run
done(), then(), and success always() callbacks execute once.
Deliver
=
🔗
Context preserved
Success handlers can call methods on the same controller object used during the async task.
Important
📝 Notes
The args parameter must be array-like — use [result] even for a single argument.
resolveWith() does not run fail() — only success and always() handlers.
After resolution, further resolveWith() or rejectWith() calls are ignored.
Prefer explicit context objects over bare this inside async callbacks.
Consumers holding only a promise() cannot call resolveWith() — only the Deferred owner settles the outcome.
Compatibility
Browser Support
deferred.resolveWith() has been available since jQuery 1.7 alongside resolve(), rejectWith(), and the full Deferred API.
✓ jQuery 1.7+
jQuery Deferred.resolveWith()
Supported in jQuery 1.7+, 2.x, and 3.x wherever jQuery Deferred runs. Part of the jQuery-specific settlement API — not in native Promises.
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
deferred.resolveWith()Universal
Bottom line: Use when done() handlers need a stable this reference. For simple result values without context, resolve() is enough.
Wrap Up
🎉 Conclusion
The deferred.resolveWith() method combines success settlement with explicit context binding. Pass your view or service as the first argument, wrap callback parameters in an array, and let done() handlers use this naturally.
Next, explore state() to inspect whether a Deferred is pending, resolved, or rejected — or review done() for the listener side of success handling.
Pass a stable context object (view, widget, logger)
Wrap arguments in an array: [result] or [status, data]
Register done() before resolving when teaching or debugging
Reuse the same context for progress, success, and failure in one flow
Pass structured result data when useful for downstream handlers
❌ Don’t
Rely on this inside setTimeout without resolveWith
Pass a raw value instead of an array as the second argument
Call resolveWith after the Deferred already settled
Confuse resolveWith (owner settles) with done() (listener registers)
Use resolveWith when plain resolve() and closure variables suffice
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about resolveWith()
Success settlement with controlled this binding.
5
Core concepts
📝01
Syntax
ctx + args[]
API
🔗02
this
= context
Binding
📦03
args
Array-like
Params
✅04
Resolved
Final state
State
With05
Family
rejectWith too
Pattern
❓ Frequently Asked Questions
resolveWith(context, args) settles the Deferred as resolved. It triggers done(), then(), and the success branch of always() handlers, with this set to context and parameters spread from the args array.
resolve(...values) passes arguments directly with default this binding. resolveWith(ctx, [a, b]) lets you choose this and wrap multiple values in an array — the same pattern as rejectWith() and notifyWith().
args must be an array or array-like object (e.g. [result] or [200, data, meta]). jQuery spreads those values as separate parameters to your done() callback.
Use it when done() handlers are methods on a UI widget, view model, or service object and you want this to refer to that object — especially inside setTimeout or AJAX callbacks where this would otherwise be lost.
No. A Deferred settles once. If it already rejected, a later resolveWith() is ignored. Likewise, rejectWith() after resolution has no effect.
Yes. resolveWith(context, args) settles with success using a custom this; rejectWith(context, args) settles with failure; notifyWith(context, args) sends interim progress — all share the same context-and-array pattern.
Did you know?
jQuery’s With methods (notifyWith, resolveWith, rejectWith) predate widespread use of arrow functions and lexical this. They let legacy jQuery code pass object context explicitly — the same problem modern code often solves with closures or class fields.