Last active
August 29, 2015 13:56
-
-
Save rndomhack/9314863 to your computer and use it in GitHub Desktop.
my "if" function.
This file contains hidden or 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 _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