1. 11
  1.  

  2. 4

    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.

    1. 2

      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”?

      1. 1

        Relevant (for Elm instead of JS, but the point stands): http://martin.janiczek.cz/clanek/being-clever-antipattern-in-elm/

      2. 1

        If only JavaScript adopted some sort of syntax shorthand for Function.prototype.call, akin to Ruby:

        irb(main):001:0> "foo; bar; baz".split(?;).map(&:strip)
        => ["foo", "bar", "baz"]
        
        1. 1

          Interesting how Swift has borrowed some Rubyisms and I guess shell-isms?

          "foo; bar; baz".split(separator: ";").map { $0.trimmingCharacters(in: .whitespaces) }
          

          And Rust too:

          "foo; bar; baz".split(";").map(|s| s.trim());
          

          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:

          map trim (split ";" "foo; bar; baz")
          
        2. 1

          Is there any advantage using this compared to simple inline function?