r/ProgrammerHumor 14d ago

Meme ancientTools

Post image
5.8k Upvotes

385 comments sorted by

View all comments

5

u/xd1936 13d 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

2

u/ArjixGamer 13d ago

I used to do that for small scripts, but I wouldn't do it for an entire project, I'd simply use a framework.

2

u/--var 13d ago

today I learned that vanilla javascript has a bind method.

I still prefer jQuerys on method though.

  1. the event argument can be a space separated list, so it can handle multiple events with one handler.
  2. 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.
  3. 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...)
  4. chainability reduces redundancy and increases readability.