开发者

Equivalent of ASP.Net Ajax Function.createDelegate in jQuery

开发者 https://www.devze.com 2023-01-30 03:21 出处:网络
I was trying to port over a ASP.Net aja开发者_Python百科x behavior into a jQuery plugin. A piece of puzzle that remains solving is to find a substitute for Function.createDelegate in jQuery.

I was trying to port over a ASP.Net aja开发者_Python百科x behavior into a jQuery plugin. A piece of puzzle that remains solving is to find a substitute for Function.createDelegate in jQuery.

I need something like this in jQuery:

this.$delegateOnClick = Function.createDelegate(this, this.fireOnClick);

Is jQuery .delegate method the way to go?

Or is it this post: Controlling the value of 'this' in a jQuery event


I think you want the jQuery $.proxy() function. There are two forms:

var proxy = $.proxy(someFunction, someObject); // A
var proxy2 = $.proxy(someObject, someString); // B

The "A" invocation returns a function such that when it's called, the function "someFunction" will be called with whatever arguments you passed the proxy and with "this" bound to "someObject". The "B" version is similar, but instead of you passing in a function you pass in the name of a property on "someObject" that refers to some function. Thus, if you have an object "widget" with a function called "blink", then

var blinker = $.proxy(widget, "blink");

gives you a function that will invoke the "blink" function on "widget" (that is, with "this" bound to "widget").

0

精彩评论

暂无评论...
验证码 换一张
取 消