Skip to content

Instantly share code, notes, and snippets.

@rndomhack
Last active August 29, 2015 13:56
Show Gist options
  • Save rndomhack/9314863 to your computer and use it in GitHub Desktop.
Save rndomhack/9314863 to your computer and use it in GitHub Desktop.
my "if" function.
function _if(val) {
function _true() {
return {
_else: function () {},
_elseif: function () {return _true}
};
}
function _false() {
return {
_else: function (cb) {cb()},
_elseif: _if
};
}
return function (cb) {
val ? cb() : void(0);
return val ? _true() : _false();
}
}
var test, i = "3";
_if (i == 1) (function () {
test = 1;
}). _elseif (i == 2) (function () {
test = 2;
}). _elseif (i == 3) (function () {
test = 3;
}). _else (function() {
test = 0;
});
console.log(test === 3); //true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment