Hi Joe.
For a minute I thought this was too niche for people at p2p to care. ;)
The Parse function is suppose to return the supplied type of enum. Given the enum:
Code:
var myEnum = { West : 1, East: 2, North : 4, South : 8 }
I would use the Parse function as
Code:
var map = { direction: Enum.Parse(myEnum, 4) }
It's practical when you have data from e.g. XML web services ect.
I did however come up with a small alteration that doesn't give me a syntax error.
Code:
Parse: function(enumtype, enumvalue){
for (var enumName in enumtype){
if(enumtype[enumName] == enumvalue)
{
return eval([enumtype + "." + enumName]);
}
}
}
But it returns [object Object].North
The idea comes from the .NET Enum class.
- mega
Moving to C# .NET