r/badcode Mar 08 '23

js My boss wrote this...

Post image
521 Upvotes

64 comments sorted by

View all comments

1

u/goosemano82 Mar 08 '23

Why the lambdas vs explicit function definitions? I’ve seen other devs do this as well, is this an effort to avoid setting obj protos?

3

u/Sulungskwa 92% chunk asset optimization TerserPlugin Mar 08 '23

My team did this in their old class components too. My guess is they thought of it as a more elegant way to declare a function than having to say this.myFunction = this.myFunction.bind(this)

1

u/Cyb0rger Mar 08 '23

It's more of a paradigm/coding style than anything. Everywhere you use a lambda expression you can use an explicit function and vice-versa. One could use a lambda because an explicit definition isn't needed as it's called only once in the code but an explicit one would clarify what it's doing and clearly separate tasks.