I am aware that you can use a closure and an anonymous function to pass arguments to an event handler, such as in:
function addClick(el, a, b) {
el.addEventListener('click', function(e) {
//a and b are available here
});
}
But the problem is, when you do it this way, you can't remove the event listener since it's anonymous. Might need to both be able to pass arguments and remove the handler at some point, so I was wondering if this is possible in some way, or if there is another method to achieve the same end.
Only thing I can think of is to add properties to the handler and access them that way:
var handler = function() {
console.log(handler.a);
console.log(handler.b);
}
handler.a = 'argument1';
handler.b = 'argument2';
el.addEventListener('click', handler);