jQuery Deferred notifyWith() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Deferred

Definition

deferred.notifyWith(context [, args]) fires progress callbacks while pending (since jQuery 1.7), with this set to context and values taken from an optional args array.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
dfd.progress(function (pct) {
  // this === context
});

dfd.notifyWith(context, [40])

notify(40)              // default this
notifyWith(ctx, [40])   // this === ctx; args as array
CallWhat it does
contextBecomes this in progress callbacks
argsArray (or array-like) of callback arguments
Return valueSame Deferred (chainable)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Create a Deferred and register .progress(fn).
Step 2Choose the object that should be this inside the handler.
Step 3Call notifyWith(context, [arg1, arg2, ...]) while pending.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Context and Percent

Pass a panel object as this and the percent in an array.

jQuery
var panel = { name: "Upload" };
var dfd = $.Deferred();

dfd.progress(function (pct) {
  console.log("panel: " + this.name);
  console.log("progress: " + pct + "%");
});

dfd.notifyWith(panel, [40]);
// panel: Upload
// progress: 40%
Try It Yourself

How It Works

  1. Context. panel becomes this inside the progress handler.
  2. Args array. [40] spreads to the first parameter pct.
  3. Read properties via this.name without closing over panel.

Example 2 — notify vs notifyWith

Plain notify does not set your object as this.

jQuery
var panel = { title: "Upload panel" };
var dfd = $.Deferred();
var lines = [];

dfd.progress(function () {
  lines.push("this.title: " + this.title);
});

dfd.notify(10);
dfd.notifyWith(panel, [20]);

console.log(lines.join("\\n"));
// this.title: undefined
// this.title: Upload panel
Try It Yourself

How It Works

  1. notify(10) — default this; this.title is undefined.
  2. notifyWith(panel, [20]) — this is panel.
  3. Same listener shows the difference clearly.

Example 3 — Multiple Arguments from an Array

Array elements become separate callback parameters.

jQuery
var ui = { id: "job-1" };
var dfd = $.Deferred();

dfd.progress(function (step, total, label) {
  console.log(this.id + ": " + step + "/" + total + " " + label);
});

dfd.notifyWith(ui, [2, 4, "sync"]);
// job-1: 2/4 sync
Try It Yourself

How It Works

  1. Array [2, 4, "sync"] maps to step, total, label.
  2. Context ui supplies this.id.
  3. One call carries structured progress data.

Frequently Asked Questions

notifyWith(context, args) calls progress callbacks while the Deferred is pending. Inside each callback, this is set to context, and values from the args array are passed as separate parameters.
notify(a, b) passes arguments directly with default this. notifyWith(ctx, [a, b]) sets this to ctx and requires args as an array (or array-like) — same pattern as resolveWith and rejectWith.
Pass an array such as [40] or [step, total, label]. jQuery spreads those elements as individual arguments to each progress callback.
No. Like notify(), it only fires progress handlers. Call resolve(), resolveWith(), reject(), or rejectWith() when the work finishes.
Use it when progress handlers need a specific this — for example a UI widget or view model — especially inside timers where this would otherwise be lost.
Yes. After the Deferred is resolved or rejected, further notifyWith() calls are ignored, and late progress handlers do not receive past progress.

Next: deferred.then() Method

Learn the legacy filter/chain API and its modern then() replacement.

deferred.then() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful