scala-style pattern matching for Javascript