طريقة jQuery $ .proxy ()

❮ طرق أحداث jQuery

مثال

فرض سياق وظيفة "الاختبار" ، داخل الكائن:

$("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).

❮ طرق أحداث jQuery