【1】構文
var Xxxx = { Aaaa: 0, Bbbb: 1, Cccc: 2, // ... };
【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
参考文献
http://motogeneralpurpose.blogspot.jp/2013/07/javascriptenum.html
http://qiita.com/you21979@github/items/98c9bd10f31d06d422ea
関連記事
Enum / Union / const assertion
https://dk521123.hatenablog.com/entry/2021/03/17/005906