Functional if in Javascript
What about this functional if/else version for Javascript?function _if(boolean, trueBody) { if(boolean) { trueBody(); } function _else(falseBody) { if(!boolean) { falseBody(); } } return { else: _else } }It can now now be used like this:
_if(booleanExpression, function() { // if body }).else(function() { // else body });Now you have an if/else body with local scope.