jQuery.proxy() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Event Handler

Definition

jQuery.proxy(function, context) returns a new function that always runs with this set to context (since 1.4). Extra arguments for partial application arrived in 1.6.

Syntax

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

jQuery
var me = { type: "zombie", test: function () { return this.type; } };

// Without proxy — this is the button
$("#btn").on("click", me.test);

// With proxy — this is me
$("#btn").on("click", $.proxy(me.test, me));

// Modern replacement
$("#btn").on("click", me.test.bind(me));
CallWhat it does
$.proxy(fn, context)Bind a function to a context
$.proxy(context, name)Bind context[name] to context
$.proxy(fn, context, …args)Also prepend extra arguments
$.proxy(context, name, …args)Name form + partial application

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

Parameters

ParameterDescription
fnUsed in $.proxy(fn, context). Bind a function to a context
contextUsed in $.proxy(fn, context). Bind a function to a context
nameUsed in $.proxy(context, name). Bind context[name] to context
argsUsed in $.proxy(fn, context, …args). Also prepend extra arguments

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Function + Context

Lock this to your object when the handler runs.

jQuery
var me = {
  type: "zombie",
  test: function (event) {
    $("#out").text("Hello " + this.type);
    // element is still available:
    // event.target
  }
};

$("#test").on("click", $.proxy(me.test, me));
Try It Yourself

How It Works

  1. Method. me.test expects this to be me.
  2. Proxy. $.proxy(me.test, me) returns a wrapped function.
  3. Click. jQuery calls the wrapper; this stays me.

Example 2 — Context + Method Name

Pass the object and the method name as a string.

jQuery
var obj = {
  name: "John",
  test: function () {
    $("#out").text(this.name);
  }
};

$("#test").on("click", $.proxy(obj, "test"));
Try It Yourself

How It Works

  1. Lookup. jQuery reads obj["test"].
  2. Bind. That function is locked to obj as this.
  3. Click. Handler prints obj.name.

Example 3 — Extra Arguments

Prepend values; the event object still arrives last.

jQuery
var me = {
  type: "dog",
  test: function (one, two, event) {
    $("#out").text(
      one.type + " / " + this.type + " / " + two.type + " / " + event.type
    );
  }
};
var you = { type: "cat" };
var they = { type: "fish" };

$("#test").on("click", $.proxy(me.test, me, you, they));
Try It Yourself

How It Works

  1. Extras. you and they are bound as the first two args.
  2. Context. this is still me ("dog").
  3. Event. jQuery appends the event object after the extras.

Frequently Asked Questions

jQuery.proxy(function, context) returns a new function that always runs with this set to context, no matter where it is called. That fixes event handlers where this would otherwise be the DOM element.
Yes. As of jQuery 3.3, prefer native Function.prototype.bind(). $.proxy() still works in jQuery 3.x for legacy code, but new projects should use fn.bind(context).
Both lock this. $.proxy(fn, ctx) is jQuery’s version (since 1.4). It also accepts $.proxy(context, "methodName"). Native bind is the modern standard and needs no jQuery.
Passing obj.handle to .on("click", obj.handle) makes this the clicked element inside handle. $.proxy(obj.handle, obj) keeps this as obj so you can read properties and call other methods.
jQuery can often .off() using the original function, but proxied copies of the same function share tracking. Prefer unique namespaces: .on("click.myWidget", $.proxy(fn, ctx)) then .off("click.myWidget").
Yes, since 1.6: $.proxy(fn, ctx, arg1, arg2). Those args come first; later call-time args (like the event) follow. Since 1.9, a null/undefined context keeps the caller’s this for partial application only.

Next: .delegate() Method

Attach modern event handlers — with or without a fixed this.

.delegate() 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.

8 people found this page helpful