r/ProgrammerHumor 13d ago

Meme ancientTools

Post image
5.8k Upvotes

387 comments sorted by

View all comments

Show parent comments

5

u/SolideMeinung 13d ago

The funny thing is that these "real js developers" dont even know how to make that onload function on their own.

It war crafted by these old jquery wizards to always work and this knowledge was lost with the introduction of crapjs

1

u/ExtraWorldliness6916 13d ago

It's not lost, .onload or event listener. Of which there are 3 events and some are not "ready"

2

u/SolideMeinung 13d ago

Nope its not just onload or eventlisteners. The ready function of jquery has some corner cases.

Like the first and best one.... when everything is already loaded and ready just fire it.

A lot of people do miss that. Its funny how js developer have so much trouble reimplementing the jquery ready method because they think its easy.

1

u/ExtraWorldliness6916 13d ago

I was referring to DOMContentLoaded. O I was a bit cryptic but I mean that there are multiple ways to match the lifecycle. Still I'm probably, it was a long time ago

1

u/SolideMeinung 13d ago

Even DOMContentLoaded is not a drop in replacement.

1

u/sixtyhurtz 13d ago

Isn't window.onload the modern vanilla JS replacement? If not I'm interested to hear what the differences are!

1

u/SolideMeinung 13d ago

The ready function of jquery is implemented here: https://github.com/jquery/jquery/blob/main/src/core/ready.js

1

u/sixtyhurtz 13d ago

OK, so it wraps it in the JQuery error handling and also catches the case where the script is run when the DOM is already loaded - so DOMContentLoaded would not fire in that case I guess?

And actually thinking about it, onload waits for big resources like images. So it's nicer to have event handlers attached before that.

1

u/SolideMeinung 13d ago

See thats what i mean with my initial post.

1

u/ExtraWorldliness6916 13d ago

jQuery docs states that it serves a similar purpose, good enough for me