I want to call two functions when myValue changes, and while this works just fine:
this.myValue.on("change", $.proxy(self.functionOne, self));
this.myValue.on("change", $.proxy(self.functionTwo, self));
neither function is called in this case:
this.myValue.on("change", function () {
$.proxy(self.functionOne, self);
$.proxy(self.functionTwo, self);
})
It isn't a huge deal to me if I can't call both functions within one change event like this right now, but I'm pretty new to jQuery and would like to learn why.
You need to call the functions defined in the $.proxy()
:
this.myValue.on("change", function () {
$.proxy(self.functionOne, self)();
$.proxy(self.functionTwo, self)();
})
Note the trailing ()
.
The $.proxy
method will just return a function, but not call it. You can use:
self.functionOne.call(self);
self.functionTwo.call(self);
The call function calls the function, and you get to pass in the 'context' ie. what gets used as 'this' within the function, much like in $.proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With