Created
June 20, 2012 21:13
-
-
Save DimitarChristoff/2962269 to your computer and use it in GitHub Desktop.
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
$.if = function(){ | |
var truthy = 1; | |
for (var i = 0; i < arguments.length; i++){ | |
if (!arguments[i]){ | |
truthy = 0; | |
break; | |
} | |
} | |
var run = function(fn){ | |
fn(); | |
return methods; | |
}; | |
var fake = function(fn){ | |
return methods; | |
}; | |
var allMethods = { | |
1: {then: run, else: fake}, | |
0: {then: fake, else: run}, | |
}; | |
var methods = allMethods[truthy]; | |
return methods; | |
}; | |
$.if(true).then(function(){ | |
console.log(true); | |
}).else(function(){ | |
console.log(false); | |
}); | |
$.if(false).then(function(){ | |
console.log(true); | |
}).else(function(){ | |
console.log(false); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment