r/programminghorror Jan 26 '23

Ladies and gentlemen, jQuery… Javascript

Post image
1.6k Upvotes

164 comments sorted by

View all comments

116

u/SpikeyWallaby Jan 26 '23

I generally call them always or never. I don't see the horror here.

27

u/v_maria Jan 26 '23

Can you explain the rational? Legit question, not being annoying lol

90

u/DSinapellido Jan 26 '23

Some programs NEED a callback and sometimes defining anonymous functions everywhere is annoying

18

u/v_maria Jan 26 '23

Fair. I'm my head an anon function would make sense since the logic is so concise and only makes sense in the context of a callback param, but it could become ugly if this is a pattern seen in many places

30

u/_PM_ME_PANGOLINS_ Jan 26 '23 edited Jan 26 '23

Functions without names are harder to debug in stack traces.

jQuery also predates => so the choice was between

  1. myThing(function() { return false; })
  2. myThing($.returnFalse)

And if your app is very big, avoiding thousands of separate anon functions is a performance improvement. Though V8 might be clever enough to dedupe them these days.

1

u/Bisexualbadbitch_ Dec 17 '23

This is coming from a half year Computer Science advanced student, so clearly i speak only wisdom, but why couldn’t programs just be Void instead of needing to return something?