addEventListener Two Functions

前端 未结 3 641
半阙折子戏
半阙折子戏 2020-12-05 18:35

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

3条回答
  •  广开言路
    2020-12-05 19:07

    Wrap your functions in a function. But need to send all params from addEventListener callback (paramter event)

    const callbackOne = (...props) => {
        console.log('callbackOne', ...props)
    };
    const callbackTwo = (...props) => {
        console.log('callbackTwo', ...props)
    };
    
    element.addEventListener('eventName',(...props) => {    
         callbackOne(...props);  
         callbackTwo(...props);
    });
    

    You

提交回复
热议问题