jQuery proxy() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Utilities

Definition

jQuery.proxy() (alias $.proxy) returns a new function that always runs with a chosen this value (added in jQuery 1.4). It is mainly used so object methods keep the right this when used as event handlers.

Syntax

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

jQuery
$.proxy(fn, context)           → bound function
$.proxy(context, "methodName") → bound method by name

// Without proxy: this → DOM element
// With proxy:    this → your object

// Modern equivalent:
fn.bind(context)
CallWhat it does
function / nameFunction to wrap, or method name string on context
contextObject used as this (or null to keep call-site this)
Extra argsPrepended to each call (since jQuery 1.6)
ReturnNew function with fixed context

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

Parameters

ParameterDescription
Step 1Decide the object that should own this inside the handler.
Step 2Call $.proxy(fn, context) or $.proxy(context, "name").
Step 3Optionally pass extra arguments (jQuery 1.6+) to pre-fill parameters.

Return Value

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

jQuery Examples

Example 1 — Lock this with Function + Context

Official pattern: keep this on your object, not the caller.

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

var raw = you.test.call({ type: "element" });
var locked = $.proxy(you.test, you).call({ type: "element" });

console.log(raw);     // "element"
console.log(locked);  // "person"
Try It Yourself

How It Works

  1. Raw call. .call({ type: "element" }) forces this to that object.
  2. Proxy. $.proxy(you.test, you) returns a wrapper that ignores the caller’s this.
  3. Locked. Even with the same .call(...), the wrapper still uses you.

Example 2 — Context + Method Name

Official second signature: look up the method by string name.

jQuery
var obj = {
  name: "John",
  test: function () {
    return this.name;
  }
};

var handler = $.proxy(obj, "test");

console.log(handler());                    // "John"
console.log(handler.call({ name: "X" }));  // "John"
Try It Yourself

How It Works

  1. Lookup. $.proxy(obj, "test") uses obj.test as the function.
  2. Context. Calls always use obj as this.
  3. Stable. A second .call with another object still prints "John".

Example 3 — Pre-fill Extra Arguments

Since jQuery 1.6, extra args are prepended before the normal call args.

jQuery
var me = {
  type: "dog",
  test: function (one, two) {
    return one.type + " / " + this.type + " / " + two.type;
  }
};

var proxy = $.proxy(me.test, me, { type: "cat" }, { type: "fish" });

console.log(proxy());  // "cat / dog / fish"
Try It Yourself

How It Works

  1. Extra args. cat and fish are baked into the proxy.
  2. Order. They become one and two before any later call arguments.
  3. Context. this.type is still "dog" from me.

Frequently Asked Questions

jQuery.proxy() takes a function and returns a new function that always runs with a fixed this context. It is most useful for attaching object methods as event handlers so this inside the handler refers to your object, not the DOM element that fired the event.
jQuery.proxy(function, context) wraps a function with a chosen this value. jQuery.proxy(context, "methodName") looks up a method on an object by name and returns a bound version. Since jQuery 1.6 you can also pass extra arguments that are prepended to each call.
Both fix this and can pre-fill arguments. Native bind() is the modern standard. jQuery.proxy() was deprecated in 3.3; it also participates in jQuery's event tracking so .off() can match the original function in some cases — still prefer unique event namespaces when unbinding.
When you pass obj.handleClick directly to .on("click", obj.handleClick), JavaScript sets this to the clicked element. $.proxy(obj.handleClick, obj) returns a wrapper where this is always obj.
Not for new code. Prefer fn.bind(context) or arrow functions. Keep $.proxy only while maintaining legacy jQuery code that already uses it.
jQuery's event system can treat proxied wrappers as one identity. Binding $.proxy(fn, ctxA) and $.proxy(fn, ctxB), then calling .off with either proxy, may remove both. Use namespaced events like click.myHandler1 for safe unbind.
As of jQuery 1.9, a null or undefined context means the proxied function keeps the this value from the call site. That lets you partially apply arguments without forcing a new this.

Next: jQuery.noop() Method

Learn how jQuery escapes special characters in CSS selectors.

jQuery.noop() 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