Example 1 — Custom this in fail()
Pass a context object so the fail handler can read this.id.
var ctx = { id: "uploader" };
var dfd = $.Deferred();
dfd.fail(function (reason) {
console.log(this.id + ": " + reason); // uploader: timeout
});
dfd.rejectWith(ctx, ["timeout"]); How It Works
- Define context.
ctxholds anidthe handler needs. - Attach fail. The callback uses
this.idand the reason arg. - Reject with context.
rejectWith(ctx, ["timeout"])setsthis.

