Skip to content

Instantly share code, notes, and snippets.

@NobukazuHanada
Last active August 29, 2015 14:00
Show Gist options
  • Save NobukazuHanada/11322279 to your computer and use it in GitHub Desktop.
Save NobukazuHanada/11322279 to your computer and use it in GitHub Desktop.
var Switch = function(expr){
return new YetSucceed(expr);
}
var Succeed = { case : function(cond,proc){ return this; } };
var YetSucceed = function(expr){};
YetSucceed.prototype.case = function(cond, proc){
if(cond){
proc();
return Succeed;
}
return this;
}
var x = 0;
new Switch(true).
case(x > 0, function(){
console.log(x + " is positive.");
}).
case(x === 0, function(){
console.log(x + " is zero. ");
}).
case(x < 0, function(){
console.log(x + " is negative . ");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment