jQuery $.proxy()Method
Examples
Force the context of the "test" function inside objPerson:
$("button").click($.proxy(objPerson,"test"));
Try it Yourself »
Definition and Usage
The $.proxy method accepts an existing function and returns a new function with a specific context.
This method is often used to add events to elements whose context points to a different object.
Tip:If you bind the function returned from $.proxy, jQuery can still unbind the correct function by passing the original function.
Syntax 1
$(selector).proxy(function,context)
Try it Yourself
Syntax 2
$(selector).proxy(context,name)
Try it Yourself
| Parameters | Description |
|---|---|
| function | The existing function to be called. |
| context | The name of the object on which the function resides. |
| name | The existing function whose context will be changed (should be a property of the context object). |
Other Extensions
jQuery Event Methods