Содержание:
jQuery.proxy( function, context )Возвращает: Function
Описание: По заданной функции, создает другую такую же, внутри которой переменная this будет равна заданному значению.
-
Добавлен в версии: 1.4jQuery.proxy( function, context )
-
functionТип: Function()The function whose context will be changed.
-
contextТип: PlainObjectThe object to which the context (
this
) of the function should be set.
-
-
Добавлен в версии: 1.4jQuery.proxy( context, name )
-
contextТип: PlainObjectThe object to which the context of the function should be set.
-
nameТип: StringThe name of the function whose context will be changed (should be a property of the
context
object).
-
-
Добавлен в версии: 1.6jQuery.proxy( function, context [, additionalArguments ] )
-
functionТип: Function()The function whose context will be changed.
-
contextТип: PlainObjectThe object to which the context (
this
) of the function should be set. -
additionalArgumentsТип: AnythingAny number of arguments to be passed to the function referenced in the
function
argument.
-
-
Добавлен в версии: 1.6jQuery.proxy( context, name [, additionalArguments ] )
-
contextТип: PlainObjectThe object to which the context of the function should be set.
-
nameТип: StringThe name of the function whose context will be changed (should be a property of the
context
object). -
additionalArgumentsТип: AnythingAny number of arguments to be passed to the function named in the
name
argument.
-
This method is most useful for attaching event handlers to an element where the context is pointing back to a different object. Additionally, jQuery makes sure that even if you bind the function returned from jQuery.proxy()
it will still unbind the correct function if passed the original.
Be aware, however, that jQuery's event binding subsystem assigns a unique id to each event handling function in order to track it when it is used to specify the function to be unbound. The function represented by jQuery.proxy()
is seen as a single function by the event subsystem, even when it is used to bind different contexts. To avoid unbinding the wrong handler, use a unique event namespace for binding and unbinding (e.g., "click.myproxy1"
) rather than specifying the proxied function during unbinding.
As of jQuery 1.6, any number of additional arguments may be supplied to $.proxy()
, and they will be passed to the function whose context will be changed.
As of jQuery 1.9, when the context
is null
or undefined
the proxied function will be called with the same this
object as the proxy was called with. This allows $.proxy()
to be used to partially apply the arguments of a function without changing the context.