Created
December 5, 2015 06:53
-
-
Save ivancorrales/d108cc0dccc1fad460ae to your computer and use it in GitHub Desktop.
Avoiding using if-else statements
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
function _ifElseFn(condition, cb, cb2){ | |
var result = {true:cb,false:cb2}; | |
return result[condition](); | |
} | |
function sayYourCarIsOld(){ | |
console.log('your car is old'); | |
} | |
function sayYourCarIsNew(){ | |
console.log('your car is new'); | |
} | |
var newCar = false; | |
_ifElseFn(newCar,sayYourCarIsNew,sayYourCarIsOld); | |
newCar = true; | |
_ifElseFn(newCar,sayYourCarIsNew,sayYourCarIsOld); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment