Skip to content

Instantly share code, notes, and snippets.

@NobukazuHanada
Last active August 29, 2015 14:00
Show Gist options
  • Save NobukazuHanada/11306952 to your computer and use it in GitHub Desktop.
Save NobukazuHanada/11306952 to your computer and use it in GitHub Desktop.
var Switch = function(expr){
this.successed = false;
this.case = function(cond, proc){
if( !this.successed && cond === expr){
this.successed = true;
proc();
}
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