wesbos / Wes-Bos-Video-Notes

These are notes that supplement the videos on Wes Bos Courses
73 stars 301 forks source link

Playing with CSS Variables and JS #46

Closed ptrnln closed 5 days ago

ptrnln commented 5 days ago

Minor nitpick but I noticed in your event handlers you tend to use this rather than event.target, where the latter would greatly improve code clarity, modularity and DRYness since event.target will always refer to the element that dispatched the event, a.k.a the element the user interacted with, whereas this refers to the element the handler was attached to. So if you have an element that has several children expected to have the same functionality, you can simply append the event handler for that functionality to the parent and you would have fewer event listeners, which generally means less memory usage, no?

wesbos commented 5 days ago

Hey! Yeah, I usually use target or currentTarget, but it reaaaaly doesn't matter that much. I've never seen any issues with memory or DRY code. Next time I re-record I'll use the event.