fold JavaScript functions