Posted By

1man on 04/27/11


Tagged

object Switch flow


Versions (?)

Switch using an Object


 / Published in: JavaScript
 

URL: http://jqfundamentals.com/book/index.html

Using an object as a simple switch.

  1. var noSwitch = {
  2. "opt1": function(){
  3. alert("opt1");
  4. },
  5. "opt2": function(){
  6. alert("opt2");
  7. },
  8. "default": function(){
  9. alert("default");
  10. }
  11. }
  12.  
  13. var foo;
  14. var foo = "opt1";
  15. var foo = "opt2";
  16.  
  17. if(noSwitch[foo]){
  18. noSwitch[foo]();
  19. } else {
  20. noSwitch['default']();
  21. }

Report this snippet  

You need to login to post a comment.