Skip to content

Instantly share code, notes, and snippets.

@pedroassis
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroassis/9ab28b46d32e70882a5a to your computer and use it in GitHub Desktop.
Save pedroassis/9ab28b46d32e70882a5a to your computer and use it in GitHub Desktop.
Functional way for a if statement
// Just to be sure ;)
if (!Boolean.prototype.is)
{
Boolean.prototype.is = function(fun /*, thisArg */)
{
'use strict';
if (this === void 0 || this === null){
throw new TypeError();
}
var type = typeof fun;
if (type !== 'function'){
throw new TypeError(type + " is not a function");
}
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
if(this){
return fun.call(thisArg);
}
return this;
};
}
var aBool = true;
if(aBool){
alert("it is");
}
// Even better
aBool.is(function(){
alert("It is better ?");
});
// Chaining possible
aBool.is(function(){
alert("It is better ?");
return ttrue;
}).is(function(){
alert("It is worse ?");
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment