I note that it's recommended to use named functions when binding an event handler to a javascript event. How can I do this when my function needs to be passed the this
object?
For example, how would I replace the anonymous function below by directly calling doFancyStuff
:
$(document).on('change', 'input.fancy-textbox', function () {
doFancyStuff($(this));
});
function doFancyStuff($textbox) {
// fanciness
}
Extra points if you point out other conventions I might be breaking with the above code.
To clarify, I want to call the doFancyStuff()
method in my example from multiple places, otherwise yes, I could just do something like this:
$(document).on('change', 'input.fancy-textbox', doFancyStuff);
function doFancyStuff() {
var $textbox = $(this);
// fanciness
}