in the last part of the video the event listener is set to once true but won't we need it later?
Kevin Powell
YouTube
I made a BIG mistake
I think it's important to highlight when we've made past mistakes and show the right way to do it when we find those mistakes.
🔗 Links
✅ The finished code: https://codepen.io/kevinpowell/pen/BaVdrLm
✅ More on Visually Hidden: https://www.scottohara.me/blog/2017/04/14/inclusively-hidden.html
📚 Resources I used to help make this video:
✅ AcceD...
10 Replies
it gets re-added every time the click handler runs on the close button closeMenu function runs
okay but it gets removed then readded once
right?
once here does not mean only ever run once
once
here means "this specific event listener is gone after it runs"nope, the handler gets added every single time
closeMenu
runs, and runs once only and then removes itself again. Then, when closeMenu
runs again, it gets re-added and runs onceAnd since it's being added each time the
closeMenu()
function is run, it'll happen once per closeso it is removed from memory right?
indeed
okay cool now i get it i was worried it would run once and only once XD till next refresh
it reminds me of angular rx js
is it similar in anyway by any chance?
Angular is JS so…yeah, it's probably very similar lol
rxjs had like subscribe and unsubscribe anyway i leave that for another post
thank you both for the answers ^^