Passing A Method For Later Evaluation
If I pass a function as an argument, and the function is a jQuery method, will calling the passed function later still correctly set this? I thought it would, but calling the funct
Solution 1:
Try using bind
:
The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
evaluators.push($input.val.bind($input));
It is worth noting bind
is not supported on older browsers (e.g. IE8 and FF3 (or older)).
Solution 2:
Please refer to jQuery.proxy() to see how context or this
of the function can be set.
Post a Comment for "Passing A Method For Later Evaluation"