Friday, December 11, 2009

JavaScript Enum

JavaScript Enum variable enables you to create the collection of integer based constant values. In this sample we will learn the different type of JavaScript Enum variable syntaxes and retrieving their integer values using special way to get Enum items. Try the sample code below:
<html>
<head>

    <title>Creating Javascript Enum Items</title>
   
</head>
<body onload="Enum()">

    <script type="text/javascript">

    var Days = {"sunday" : 0, "monday" : 1, "tuesday" : 3, "wednesday" : 4, "thursday" : 5, "friday" : 6, "saturday" : 7};

    document.write("<b>Day Names Enumerator=</b> " + Days.friday + "<br />");

    /************************************************************/
   
    function Enum() {}

    Enum.ColorType = {red:0, blue:1, green:2}

    document.write("<b>Enum Function=</b> " + Enum.ColorType.blue + "<br />");

    /************************************************************/
   
    var enumObj = new Object();

    enumObj.fontSize = {small:10, medium:12, large:14}

    document.write("<b>Enum Object=</b> " + enumObj.fontSize.small + "<br />");

    </script>

</body>
</html>

--
ఇట్లు మీ,
చంద్రశేఖర్.

No comments: