What would it be like without Arrow Function?

Asked

Viewed 45 times

-1

What would that be like without Arrow Function?

document.querySelector('.menu .backdrop').addEventListener('click', e => {

    document.querySelector('header .menu').classList.remove('open');

});

2 answers

3

Would be using a normal function:

document.querySelector('.menu .backdrop').addEventListener('click', function (e) {

    document.querySelector('header .menu').classList.remove('open');

});
  • The "e" is doing what in this function?

  • It is the object of the event that the JS will pass

1

Replace the e => for function(e) :

document.querySelector('.menu .backdrop').addEventListener('click', function(e) {
  document.querySelector('header .menu').classList.remove('open');
});
.open {
  background-color: green;
}
<div class="menu">
  <div class="backdrop">
    Clique
  </div>
</div>

<header>
  <div class="menu open">
    Vai sumir...
  </div>
</header>

  • The "e" is doing what in this function?

  • It is the JS event, in both examples, you will receive the e as parameter, which will be an event object click.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.