Refactored the JavaScript generation code for enums.