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). |