addEventListener Two Functions

Alex picture Alex · Jul 30, 2014 · Viewed 33.6k times · Source

How can I make it so that addEventListener() has two functions inside it?

I have tried finding my own solution, but none seem not to work. Please give me example if it is possible.

Answer

Sten Muchow picture Sten Muchow · Jul 30, 2014

Wrap your functions in a function.

const invokeMe = () => console.log('I live here outside the scope');
const alsoInvokeMe = () => console.log('I also live outside the scope'); 

element.addEventListener('event',() => {    
     invokeMe();
     alsoInvokeMe();    
});