Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Created June 20, 2012 21:13
Show Gist options
  • Save DimitarChristoff/2962269 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/2962269 to your computer and use it in GitHub Desktop.
$.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