【JS】JavaScriptの列挙型

■ 構文

var Xxxx = {
    Aaaa:   0,
    Bbbb: 1,
    Cccc:  2,
    // ...
};

■ サンプル

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sample</title>  
</head>
<body>
<div id="result"></div>
</body>
<script type="text/javascript" charset="UTF-8">
var ControlType = {
    None:   0,
    Textbox: 1,
    RadioButton:  2,
    Selectbox:  3,
    Checkbox: 4,
};

var resultValue = "ControlType.Selectbox = " + ControlType.Selectbox + "\n";

for (var keyValue in ControlType) {
  resultValue = resultValue + keyValue + " : " + ControlType[keyValue] + "\n";
}

document.getElementById("result").innerText = resultValue;
</script>
</html>

出力結果

ただFirefoxだと表示されなかった
ControlType.Selectbox = 3
None : 0
Textbox : 1
RadioButton : 2
Selectbox : 3
Checkbox : 4