r/programminghorror
•
u/Leonnee
•
Jun 12 '25
•
1
Javascript Javascript is filled with horror
2.4k
Upvotes
View all comments
Show parent comment
1
u/LordFokas Jun 13 '25
Yeah that's not something that concerns me when picking up a language. It's point 1 again. It's so rare I don't care. And even if I cared, I'd just make a function for it. In JS you can just add methods to prototypes, so no one's stopping you from creating custom methods that do it nicely for you.
I have one custom method in the Object class and one in the Promise class in a lib I use in most of my projects. The object one doesn't matter, but the Promise one, it's very annoying when you have a Promise of an array type and need to await the promise and fuck around with parentheses to get an entry like
const value = (await array_promise)[0];especially if you want to do more stuff on it, or the promise is an already long method call. So, my Promise class has an async method called first that awaits the Promise, gets the first index, and returns it. Now you can just callconst value = await array_promise.first();which is much nicer.So yeah, whiny or not, that's not really a valid argument for JS, you can just patch any class to do anything. You shouldn't do it too much, but you can.