jQuery $.proxy() Metode
Voorbeeld
Dwing die konteks van die "toets"-funksie af, binne objPerson:
$("button").click($.proxy(objPerson, "test"));
Definisie en gebruik
Die $.proxy-metode neem 'n bestaande funksie en gee 'n nuwe een met 'n spesifieke konteks terug.
Hierdie metode word dikwels gebruik om gebeurtenisse aan 'n element te koppel waar die konteks na 'n ander voorwerp terugwys.
Wenk: As jy die funksie bind wat van $.proxy teruggestuur word, sal jQuery steeds die korrekte funksie ontbind as die oorspronklike geslaag is.
Sintaksis 1
$(selector).proxy(function,context)
Sintaksis 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). |