I see lines like this occasionally and it drives me nuts. IMO, if your code isn’t scannable and readable, it’s not good code. In this case, there’s a much simpler way to do it that is completely obvious. Maybe the author didn’t think of it, I don’t really know. But someone should’ve caught this in code review and suggested the obvious way instead.
This is one of those cases where “clever” is used as a synonym for “obfuscated.” Or am I missing something RE: modern js best practices, as hinted by the line “…we strive here to avoid creating new functions”?
But no symbol-to-proc-like thing for when you just want to call a method on each element as you map them.
This sort of thing always felt more natural to me in a functional language, something like:
I see lines like this occasionally and it drives me nuts. IMO, if your code isn’t scannable and readable, it’s not good code. In this case, there’s a much simpler way to do it that is completely obvious. Maybe the author didn’t think of it, I don’t really know. But someone should’ve caught this in code review and suggested the obvious way instead.
This is one of those cases where “clever” is used as a synonym for “obfuscated.” Or am I missing something RE: modern js best practices, as hinted by the line “…we strive here to avoid creating new functions”?
Relevant (for Elm instead of JS, but the point stands): http://martin.janiczek.cz/clanek/being-clever-antipattern-in-elm/
If only JavaScript adopted some sort of syntax shorthand for
Function.prototype.call, akin to Ruby:Interesting how Swift has borrowed some Rubyisms and I guess shell-isms?
And Rust too:
But no symbol-to-proc-like thing for when you just want to call a method on each element as you
mapthem. This sort of thing always felt more natural to me in a functional language, something like:Is there any advantage using this compared to simple inline function?