Created
December 30, 2015 12:16
-
-
Save raminious/3dfa087f8b73ed4d04ee to your computer and use it in GitHub Desktop.
Try to avoid if statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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