I have a function that registers an event handler with a callback that will receive only some of the event data.
My problem is I want to protect against the function registering multiple time by calling .off
before .on
but I'm not sure how to specify the callback to .off
in this case as it has to be the same function used by .on
For example:
function myclick(elem, callback) {
//elem.off('click', ???? ); // how should this be specified
elem.on('click', function (e) {
callback(e.target);
}
}
I am looking for a general solution that is not jQuery dependent as this can happen with any library that provides on and off functionality.