Return to Snippet

Revision: 45180
at April 27, 2011 01:17 by 1man


Initial Code
var noSwitch = {
	"opt1": function(){
		alert("opt1");
	},
	"opt2": function(){
		alert("opt2");
	},
	"default": function(){
		alert("default");
	}
}

var foo;
var foo = "opt1";
var foo = "opt2";

if(noSwitch[foo]){
	noSwitch[foo]();
} else {
	noSwitch['default']();
}

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

Initial Description
Using an object as a simple switch.

Initial Title
Switch using an Object

Initial Tags
object

Initial Language
JavaScript