0

So, I'm very new to Javascript and I've been following this javascript30.com course and it's the first day.

I'm trying to wrap my head around that removeTransition function call. How is that valid and what exactly is getting passed as 'e'?

function removeTransition(e) {
        if (e.propertyName !== "transform") return;
        e.target.classList.remove("playing");
      }

. .

const keys = Array.from(document.querySelectorAll(".key"));
      keys.forEach((key) =>
        key.addEventListener("transitionend", removeTransition)
      );
DJG
  • 65
  • 8
  • do you know python by any chance ? or any language which can use function as arguments (or in general values) . it will help people who are writing the answers – ashish singh May 22 '20 at 04:06
  • As far as I can understand , removeTransition is being called from the HTML , where e denotes an event object – Harmandeep Singh Kalsi May 22 '20 at 04:07
  • you are registering `removeTransition` function with the event listener for an event, `transistionend`. The browser event manager will invoke this function with an event (which the formal parameter, `e` of this function) – D. Seah May 22 '20 at 04:12
  • @ashishsingh I've only really programmed in Java – DJG May 22 '20 at 04:19
  • 1
    ok i will write an answer you can follow up in comments – ashish singh May 22 '20 at 04:19
  • @D.Seah oh so I'm not really invoking the function right there? I'm just saying that I want the removeTransition function to be called when the eventListener finds a transitionend event? So it's kind of just like linking a function to an event? – DJG May 22 '20 at 04:22
  • You do not invoke the function yourself, You are just registering the function for an event, `transitionend`. Browser will take care of the rest – D. Seah May 22 '20 at 04:24
  • @D.Seah I understand it's registering the function for an event now, but can you explain what exactly e is? You say it's an event, but I'm not entirely sure what that means – DJG May 22 '20 at 05:09
  • when you do `addEventListener("transitionend",`, you're telling the browser to listen to an event `transitionend`. and if this event occurs, `removeTransition` function will be called. – D. Seah May 22 '20 at 15:05

0 Answers0