Hi all!
I'm having a subtle problem with enumerations in javascript. Let me first outline the problem.
I have an enumeration in javascript (using JSON) that look like this:
var EventsToShow = {"MyEvents" : 1, "AllEvents" : 2 };
Now this is all good but when I want to parse a number (ie. 1 or 2) to an EventsToShow enum I have to use a switch statement (which is always at least 5 lines of code) like so:
switch([1 or 2])
{
case EventsToShow.MyEvents:
alert("This is an EventsToShow.MyEvents");
break;
case EventsToShow.AllEvents:
alert("This is an EventsToShow.AllEvents");
break;
}
My question is: Is there a simple way to parse an Enum to a number (integer) and vice versa, perhaps using eval?
Cheers, Jon!
This is a cross-post (
http://p2p.wrox.com/topic.asp?TOPIC_ID=58984).
- mega
Moving to C# .NET