generalize javascript class approach