I don’t quite understand what your code is trying to do, but you can make variables available in any event handler, taking advantage of function closures:
function addClickHandler(elem, arg1, arg2) { elem.addEventListener('click', function(e) {
Depending on your specific coding situation, you can almost always make some kind of closure to keep access to the variables for you.
From your comments, if what you are trying to do is:
element.addEventListener('click', func(event, this.elements[i]))
You can then do this with a self-executing function (IIFE) that captures the required arguments in the closure as it executes and returns the actual event handler function:
element.addEventListener('click', (function(passedInElement) { return function(e) {func(e, passedInElement); }; }) (this.elements[i]), false);
For more information on how IIFE works, see these other links:
Javascript wrapping code inside an anonymous function
Expression with immediate function call (IIFE) in JavaScript - jQuery Pass
What are some good use cases for self-executing anonymous JavaScript functions?
This latest version may be easier to see that it does so:
// return our event handler while capturing an argument in the closure function handleEvent(passedInElement) { return function(e) { func(e, passedInElement); }; } element.addEventListener('click', handleEvent(this.elements[i]));
You can also use .bind() to add arguments to the callback. Any arguments you pass .bind() will be added before the arguments that the callback itself will have. So you can do this:
elem.addEventListener('click', function(a1, a2, e) {