Skip to content

Instantly share code, notes, and snippets.

@kareniel
Created March 15, 2018 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kareniel/2abf246b07b58f366be20435507ac3ba to your computer and use it in GitHub Desktop.
Save kareniel/2abf246b07b58f366be20435507ac3ba to your computer and use it in GitHub Desktop.
make use of objects and numbers to make custom enums

option a

i use uppercase to make more explicit the use of a constant

var directions = { UP : 0, RIGHT: 1, ... }

this.direction = directions.UP

option b

other option can is:

var DIRECTIONS = { 'up' : 0, 'right': 1, ... }

this.direction = DIRECTIONS['up']

which allows you to translate your number back to it's original string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment