javascript refactor oo