I didn’t find the function prototype of addEventListener. In daily use, my feeling is that it is. After addEventListener captures the trigger event, add () to the calling function name to call . Then
btn.addEventListener('click',fn,false);
After the
listening event addEventListener captures the click event, the function executed is fn() addEventListener has the disadvantage that it cannot add parentheses with parameters, that is, it cannot capture the click and then execute fn(1,2). So usually, I use an anonymous function function(){fn(1,2)} as the binding function. Then the code becomes like this:
Why do so many people dislike it? I think it’s a good problem. Closure can solve it
I don’t know what you want to send.
But you can define fn as a function that returns a function. Basically meet the needs...
Try this?
I didn’t find the function prototype of addEventListener. In daily use, my feeling is that it is. After
After theaddEventListener captures the trigger event, add () to the calling function name to call .
Then
listening event addEventListener captures the click event, the function executed is fn()
addEventListener has the disadvantage that it cannot add parentheses with parameters, that is, it cannot capture the click and then execute fn(1,2).
So usually, I use an anonymous function function(){fn(1,2)} as the binding function. Then the code becomes like this:
After capturing the click event, the triggered function is
function(){fn(1,2)}()
You can trigger a parameterized function like fn(1,2).
I’m not very familiar with the addEventListener function, welcome to discuss and correct me.