jQuery $ .proxy()メソッド
例
objPerson内で「テスト」関数のコンテキストを適用します。
$("button").click($.proxy(objPerson, "test"));
定義と使用法
$ .proxyメソッドは既存の関数を受け取り、特定のコンテキストを持つ新しい関数を返します。
このメソッドは、コンテキストが別のオブジェクトを指している要素にイベントをアタッチするためによく使用されます。
ヒント: $。proxyから返された関数をバインドした場合でも、元の関数が渡された場合、jQueryは正しい関数のバインドを解除します。
構文1
$(selector).proxy(function,context)
構文2
$(selector).proxy(context,name)
Parameter | Description |
---|---|
function | The existing function to be called |
context | The name of the object where the function lies |
name | The existing function whose context will be changed (should be a property of the context object). |