E
E
Elena2020-05-13 19:48:45
JavaScript
Elena, 2020-05-13 19:48:45

Is it possible through a listener to add parameters to a function?

Hello everyone) Here I wondered if we have an addEventListener listener, we pass an event and a function name in it. So now you can't add parameters to this function? Here is a code example:

function item() {
 какой-то код
}
addEventListener('input', item);

How can I now pass some parameter to the item function? Without a listener, I would simply call the function and pass through it. With the listener it is impossible after all so addEventListener('input', item(параметр):?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2020-05-13
@Elena0394

function itemFactory(param1, param) {
  return function item(event) {
    // param1 and param2 are available here
  }
}

document.addEventListener('input', itemFactory(true, 50));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question