Skip to content

Instantly share code, notes, and snippets.

@raminious
Created December 30, 2015 12:16
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 raminious/3dfa087f8b73ed4d04ee to your computer and use it in GitHub Desktop.
Save raminious/3dfa087f8b73ed4d04ee to your computer and use it in GitHub Desktop.
Try to avoid if statement
var response = 4;
var api = {
dispatch: function(status){
var states = {
1: api.__err,
2: api.__err,
4: api.__done
}
typeof states[status] !== 'undefined' ? states[status]() : api.__err()
}.bind(this),
__err: function(){
console.log ('err')
},
__done: function(){
console.log ('done')
}
}
api.dispatch(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment