jQuery Deferred notifyWith() Method

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

What You’ll Learn

The notifyWith() method sends progress updates like notify(), but lets you set this inside progress() callbacks and pass arguments as an array. This tutorial covers syntax, five examples, comparisons with notify() and resolveWith(), and when custom context matters.

01

Syntax

notifyWith(ctx, args)

02

context

Sets this

03

args

Array of values

04

progress()

Receives updates

05

vs notify

Context control

06

Since 1.7

With progress API

Introduction

Progress handlers often need to update a specific UI widget or view model. Inside a plain progress() callback, this may not point where you expect — especially after setTimeout or nested functions. notifyWith(context, args) solves that by binding this to your chosen object for each progress notification.

It mirrors the With family: resolveWith() for success, rejectWith() for failure, and notifyWith() for interim progress — all with the same context-and-array pattern.

Understanding the notifyWith() Method

notifyWith() is part of jQuery’s Deferred Object API (since jQuery 1.7). Calling deferred.notifyWith(context, args) invokes every progress() handler with this set to context and parameters taken from the args array.

The Deferred stays pending — just like notify(). When work completes, call resolve(), resolveWith(), or the matching reject method to settle the final outcome.

💡
Beginner Tip

The original reference used deferred.notifyWith(this, [progress]) inside setTimeout, where this is usually the global object — not your task controller. Pass an explicit context object (e.g. uploadView) instead, and always finish with resolve() when progress reaches 100%.

📝 Syntax

General form of deferred.notifyWith:

jQuery
deferred.notifyWith( context, args )

Parameters

  • context — object used as this when each progress() callback runs.
  • args — array or array-like object whose values are passed as separate arguments to progress handlers (e.g. [50] or [2, 5, "Saving"]).

Return value

  • Returns the same Deferred object for chaining further progress or settlement calls.

Minimal example

jQuery
const view = {
  label: "Import",
  report: function (pct) {
    console.log(this.label + ":", pct + "%");
  }
};

const dfd = $.Deferred();

dfd.progress(function (pct) {
  this.report(pct);
});

dfd.notifyWith(view, [40]);
dfd.resolve();

⚡ Quick Reference

GoalCode
Progress with custom thisdfd.notifyWith(ctx, [value])
Simple progress (default this)dfd.notify(value)
Listen for progressdfd.progress(fn)
Finish with same contextdfd.resolveWith(ctx, [result])
Multiple progress argsdfd.notifyWith(ctx, [a, b, c])

📋 notifyWith() vs notify() vs resolveWith()

Three related methods — progress ping, simple notify, and final success with context.

notifyWith()
ctx + args[]

Progress + this

notify()
direct args

Simpler progress

resolveWith()
ctx + args[]

Final success

State
pending

Until resolve/reject

Examples Gallery

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

📚 Getting Started

Bind progress callbacks to a view object with an explicit context.

Example 1 — Progress with a View Object

Pass a controller object as context so this.label works inside progress().

jQuery
const view = {
  label: "Import job",
  report: function (pct) {
    console.log(this.label + " → " + pct + "%");
  }
};

const dfd = $.Deferred();

dfd.progress(function (pct) {
  this.report(pct);
});

dfd.notifyWith(view, [25]);
dfd.notifyWith(view, [100]);
dfd.resolve();
Try It Yourself

How It Works

Each notifyWith(view, [pct]) call sets this to view before invoking progress handlers — no manual .bind() required.

Example 2 — Progress Bar Widget as Context

A small widget object owns the DOM update logic; progress handlers call its methods via this.

jQuery
const barWidget = {
  selector: "#upload-bar",
  setPercent: function (pct) {
    $(this.selector).css("width", pct + "%");
    console.log("Bar width:", pct + "%");
  }
};

const dfd = $.Deferred();

dfd.progress(function (pct) {
  this.setPercent(pct);
});

dfd.notifyWith(barWidget, [30]);
dfd.notifyWith(barWidget, [70]);
dfd.notifyWith(barWidget, [100]);
dfd.resolve();
Try It Yourself

How It Works

Encapsulating UI logic on a context object keeps progress handlers thin — they delegate to this.setPercent() with the correct widget reference.

📈 Practical Patterns

Compare with notify(), pass rich args, and simulate async steps safely.

Example 3 — Why Not Just notify()?

Without notifyWith(), this inside the handler is not your view object.

jQuery
const panel = { title: "Upload panel" };
const dfd = $.Deferred();

dfd.progress(function () {
  // notify() — this is NOT panel (often window in browsers)
  console.log("notify() this.title:", this.title);
});

dfd.notify(50);

dfd.progress(function () {
  // notifyWith() — this IS panel
  console.log("notifyWith() this.title:", this.title);
});

dfd.notifyWith(panel, [100]);
dfd.resolve();
Try It Yourself

How It Works

When handlers need object methods or properties, notifyWith(context, args) is clearer than fighting default this binding or wrapping every call in .call().

Example 4 — Multiple Values in the args Array

Pass step index, total, and label as separate parameters via the array.

jQuery
const wizard = {
  name: "Setup wizard",
  onStep: function (current, total, label) {
    console.log(this.name + " — Step " + current + "/" + total + ": " + label);
  }
};

const dfd = $.Deferred();

dfd.progress(function (current, total, label) {
  this.onStep(current, total, label);
});

dfd.notifyWith(wizard, [1, 3, "Account"]);
dfd.notifyWith(wizard, [2, 3, "Preferences"]);
dfd.notifyWith(wizard, [3, 3, "Review"]);
dfd.resolve();
Try It Yourself

How It Works

The second parameter must be array-like. jQuery spreads [1, 3, "Account"] into three callback parameters — same rules as resolveWith().

Example 5 — Timed Steps with Explicit Context

Fixes the reference pattern: use a stable context object inside setTimeout, then resolve at 100%.

jQuery
const task = {
  title: "Background sync",
  onProgress: function (value) {
    console.log(this.title + " → " + value + "%");
  }
};

const dfd = $.Deferred();
const steps = [20, 40, 60, 80, 100];

dfd.progress(function (value) {
  this.onProgress(value);
});

steps.forEach(function (pct, index) {
  setTimeout(function () {
    dfd.notifyWith(task, [pct]);
    if (pct === 100) {
      dfd.resolveWith(task, ["Sync complete"]);
    }
  }, 300 * (index + 1));
});
Try It Yourself

How It Works

Inside timers, never rely on bare this. Pass task as context, then call resolveWith(task, [...]) so success handlers can use the same object if needed.

🚀 Use Cases

  • File upload widgets — bind progress to an uploader instance that owns the progress bar element.
  • Multi-step wizards — pass step metadata with a wizard controller as this.
  • Background sync tasks — report percent complete from timers or workers without losing object context.
  • Form submission flows — update validation or save status on a form view model during server round-trips.
  • Consistent With-methods — use the same context for notifyWith(), resolveWith(), and rejectWith() in one workflow.

🧠 How notifyWith() Invokes Progress Handlers

1

Register

dfd.progress(fn) queues handlers expecting progress updates.

Listen
2

notifyWith

jQuery sets this = context and spreads args into each callback.

Bind
3

Repeat / settle

Call again while pending; finish with resolveWith() or resolve().

Complete
=

Context preserved

Progress and completion handlers can share the same controller object.

📝 Notes

  • The args parameter must be array-like — use [value] even for a single argument.
  • notifyWith() does not run done() or fail() — only progress() handlers.
  • After resolve or reject, further notifyWith() calls are ignored.
  • Prefer explicit context objects over bare this inside async callbacks.
  • Consumers holding only a promise() cannot call notifyWith() — only the Deferred owner emits progress.

Browser Support

deferred.notifyWith() has been available since jQuery 1.7 alongside notify() and progress().

jQuery 1.7+

jQuery Deferred.notifyWith()

Supported in jQuery 1.7+, 2.x, and 3.x wherever jQuery Deferred runs. Part of the jQuery-specific progress 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.notifyWith() Universal

Bottom line: Use when progress handlers need a stable this reference. For simple messages without context, notify() is enough.

🎉 Conclusion

The deferred.notifyWith() method combines progress updates with explicit context binding. Pass your view or widget as the first argument, wrap callback parameters in an array, and settle with resolveWith() when the job finishes.

Next, explore pipe() to transform Deferred values through a chain, or review progress() for the listener side of progress reporting.

💡 Best Practices

✅ Do

  • Pass a stable context object (view, widget, task)
  • Wrap arguments in an array: [pct] or [a, b]
  • Finish with resolve() or resolveWith()
  • Reuse the same context for progress and final settlement
  • Register progress() before the first notify

❌ Don’t

  • Rely on this inside setTimeout without notifyWith
  • Pass a raw value instead of an array as the second argument
  • Skip final resolve after the last progress update
  • Call notifyWith after the Deferred settled
  • Use notifyWith when plain notify() and closure variables suffice

Key Takeaways

Knowledge Unlocked

Five things to remember about notifyWith()

Progress updates with controlled this binding.

5
Core concepts
🔗 02

this

= context

Binding
📦 03

args

Array-like

Params
📈 04

Pending

Not final

State
With 05

Family

resolveWith too

Pattern

❓ Frequently Asked Questions

notifyWith(context, args) fires progress() handlers like notify(), but sets this inside each callback to context and passes arguments from the args array (or array-like object).
notify(value) uses the default this binding and passes arguments directly. notifyWith(ctx, [a, b]) lets you choose this and wrap multiple values in an array — the same pattern as resolveWith() and rejectWith().
args must be an array or array-like object (e.g. [percent] or [step, total, label]). jQuery spreads those values as separate parameters to your progress callback.
Use it when progress 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. Like notify(), it only triggers progress handlers while the Deferred is pending. Call resolveWith() or resolve() when work finishes successfully.
Yes. resolveWith(context, args) settles with success using a custom this; rejectWith(context, args) settles with failure; notifyWith(context, args) sends interim progress with the same context 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 pipe()

Learn how to filter and transform Deferred results in a chain.

pipe() 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