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").
精彩评论