Thursday, January 2, 2014

case/switch statements in JavaScript

I found this and was able to make something like this:

addGunkToObject: function(myString, myObject) {
   switch(myString) {
      case "foo":
         myObject.bar = "baz";
         break;
      case "qux":
         myObject.bar = "qux";
         break;
      default:
         console.log('There should not be a default failover at this thing.');
   }
   return myObject;
}

 
 

In writing this up I realized that I have already blogged of case/switch stuff in JavaScript before, but I still wanted to offer this as this code shows off the default outlier catching stuff.

No comments:

Post a Comment