Faster than a switch statement
Instead of this:
switch(x) {
  case "First":
    dosomething();
    break;
  case "first":
    dontdosomething();
    break;
  case default:
    dontdoanything();
    break;
}try this:
var switchAlternative = {
  First: dosomething,
  first: dontdosomething,
  Switch: function(opt) {
    var func = switchAlternative[opt];
    if (typeof(func) == "undefined") {
      return dontdoanything();
    }
    else {
      return func[opt]();
    }
  }
}Written by theGleep
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Performance 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
 
