today I learned that vanilla javascript has a bind method.
I still prefer jQuerys on method though.
the event argument can be a space separated list, so it can handle multiple events with one handler.
the second argument can be a comma separated selector list, so you can attach the on handler to a single parent element and have it handle dynamically mutated child elements.
jQuery handles all of the browser quirks, so it's the same syntax regardless of browser. (chrome is the new internet explorer when it comes to not following the same standards as everyone else...)
chainability reduces redundancy and increases readability.
5
u/xd1936 2d ago
Controversial, but I have done
const $ = document.querySelector.bind(document); const $$ = document.querySelectorAll.bind(document);before in small personal projects, like the Chrome and Firefox DevTools consoles do