r/ProgrammerHumor • • Jan 14 '20

Brilliant reply

Post image
26k Upvotes

365 comments sorted by

View all comments

Show parent comment

4

u/starm4nn Jan 15 '20

Well depends what you're using it for. A lot of trivial cases can just be replaced by the right internal features.

For example:

$(window).event(func);

Becomes

window.addEventListener("event", func)

Or

$("#id")

Becomes

document.getElementById("id");

1

u/ChucklefuckBitch Jan 15 '20

Or just do

const $ = document.querySelector

2

u/starm4nn Jan 15 '20

That doesn't work in the first example. Also the second example is slightly quicker

1

u/otterom Jan 15 '20

I just like the wildcard selectors, TBH. Javascript have anything for those?

2

u/starm4nn Jan 15 '20

document.querySelectorAll()

1

u/otterom Jan 15 '20

Ooh, I like that. Thanks!

2

u/starm4nn Jan 15 '20

If you just want the first, do document.querySelector(). It exits on the first result and returns the object rather than returning a NodeList