jQuery $.proxy() method
Example
Force the context of the "test" function within objPerson:
$("button").click($.proxy(objPerson,"test"));
Try it »
Definition and Usage
The $.proxy method takes an existing function and returns a new function with a specific context.
This method is typically used to add events to elements whose context points to a different object.
**Tip:** If you bind a function returned from $.proxy, jQuery can still unbind the correct function by passing the original function.
Syntax 1
$(
selector
).proxy(
function,context
)
Try it
Syntax 2
$(
selector
).proxy(
context,name
)
Try it
| Parameters | Description |
|---|---|
| function | The existing function to be called. |
| context | The name of the object in which the function resides. |
| name | The existing function whose context will be changed (should be a property of the context object). |
jQuery event methods