Skip to content

Instantly share code, notes, and snippets.

@ivanbtrujillo
Created January 4, 2017 09:17
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 ivanbtrujillo/f6d4b61c1af18c0b80e21d8ad64fe61e to your computer and use it in GitHub Desktop.
Save ivanbtrujillo/f6d4b61c1af18c0b80e21d8ad64fe61e to your computer and use it in GitHub Desktop.
Don't use switch statement, instead use objects

Stop using switch like this:

switch(value){
  case 'a':
    console.log('value a');
    break;
  case 'b':
    console.log('value b');
    break;
  default:
    console.log('Default');
}

Instead, use a more elegant way:

let valuess = {
  'a': () => { console.log('value a'); },
  'b': () => { console.log('value b'); }
};

pageModes[value]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment