javascript coding style refactor