jQuery Deferred resolveWith() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Success + context

What You’ll Learn

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

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.

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.

📝 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).

Minimal example

jQuery
const successView = {
  source: "Checkout",
  show: function (message) {
    console.log(this.source + " complete:", message);
  }
};

const dfd = $.Deferred();

dfd.done(function (message) {
  this.show(message);
});

dfd.resolveWith(successView, ["Payment confirmed"]);

⚡ Quick Reference

GoalCode
Resolve with custom thisdfd.resolveWith(ctx, [result])
Simple resolve (default this)dfd.resolve(result)
Listen for successdfd.done(fn)
Failure with same context patterndfd.rejectWith(ctx, [err])
Multiple result argsdfd.resolveWith(ctx, [status, data, meta])

📋 resolveWith() vs resolve() vs rejectWith()

Three related methods — contextual success, simple resolve, and contextual failure.

resolveWith()
ctx + args[]

Success + this

resolve()
direct args

Simpler success

rejectWith()
ctx + args[]

Failure + this

State
resolved

Locks after call

Examples Gallery

Each example shows how resolveWith() binds this for success handlers. Use the Try-it links to run them interactively.

📚 Getting Started

Bind success callbacks to a handler object with an explicit context.

Example 1 — Success with a Handler Object

Pass a success reporter as context so this.source works inside done().

jQuery
const successHandler = {
  source: "Payment API",
  report: function (message) {
    console.log(this.source + " succeeded:", message);
  }
};

const dfd = $.Deferred();

dfd.done(function (message) {
  this.report(message);
});

dfd.resolveWith(successHandler, ["Payment confirmed"]);
Try It Yourself

How It Works

resolveWith(successHandler, [message]) sets this to successHandler before invoking done handlers — no manual .bind() required.

Example 2 — Dashboard View Shows Success Message

A dashboard view object owns the UI update logic; success handlers call its methods via this.

jQuery
const dashboardView = {
  panelId: "#stats-panel",
  showSuccess: function (summary) {
    console.log("Panel " + this.panelId + " updated:", summary);
  }
};

const dfd = $.Deferred();

dfd.done(function (summary) {
  this.showSuccess(summary);
});

dfd.resolveWith(dashboardView, ["42 new users today"]);
Try It Yourself

How It Works

Encapsulating UI logic on a context object keeps success handlers thin — they delegate to this.showSuccess() with the correct panel reference.

📈 Practical Patterns

Compare with plain resolve(), pass rich result tuples, and resolve from async callbacks safely.

Example 3 — resolveWith() vs resolve()

Without resolveWith(), this inside done() is not the handler object.

jQuery
const logger = {
  tag: "SYNC",
  log: function (msg) {
    return this.tag + ": " + msg;
  }
};

const dfdPlain = $.Deferred();
dfdPlain.done(function (msg) {
  console.log("plain resolve →", typeof this.tag, msg);
});
dfdPlain.resolve("Data loaded");

const dfdWith = $.Deferred();
dfdWith.done(function (msg) {
  console.log("resolveWith →", this.log(msg));
});
dfdWith.resolveWith(logger, ["Data loaded"]);
Try It Yourself

How It Works

Plain resolve() does not set this to your logger. resolveWith(logger, [msg]) does — the reason the With methods exist.

Example 4 — Multiple Resolution Arguments in an Array

Pass HTTP-style success tuples — done() receives them as separate parameters.

jQuery
const apiClient = {
  name: "Users API",
  onSuccess: function (status, data, meta) {
    console.log(this.name + ":", status, data.count, "users", meta.cached ? "(cached)" : "");
  }
};

const dfd = $.Deferred();

dfd.done(function (status, data, meta) {
  this.onSuccess(status, data, meta);
});

dfd.resolveWith(apiClient, [200, { count: 128 }, { cached: true }]);
Try It Yourself

How It Works

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
const uploadService = {
  label: "Photo upload",
  handleSuccess: function (message) {
    console.log(this.label + " finished:", message);
  }
};

const dfd = $.Deferred();

dfd.done(function (message) {
  this.handleSuccess(message);
});

setTimeout(function () {
  dfd.notifyWith(uploadService, [100]);
  dfd.resolveWith(uploadService, ["Upload complete"]);
}, 400);
Try It Yourself

How It Works

Inside timers, pass uploadService as context for both final progress and success — the same object can drive the whole workflow with the With methods.

🚀 Use Cases

  • Widget success UI — bind done handlers to a widget that renders confirmation messages in the DOM.
  • API response handling — pass an HTTP client or logger as this with status codes and payload data.
  • Animation completion — resolve with a scene controller as context when transitions finish.
  • Deferred chains — resolve at any stage with consistent context for downstream done() handlers.
  • Consistent With-methods — use the same context for notifyWith(), resolveWith(), and rejectWith() in one workflow.

🧠 How resolveWith() Invokes Success Handlers

1

Register

dfd.done(fn) queues handlers expecting success notifications.

Listen
2

resolveWith

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.

📝 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

🎉 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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about resolveWith()

Success settlement with controlled this binding.

5
Core concepts
🔗 02

this

= context

Binding
📦 03

args

Array-like

Params
04

Resolved

Final state

State
With 05

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.

Continue to state()

Learn how to inspect whether a Deferred is pending, resolved, or rejected.

state() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful