9.5 Code Generation
An enum declaration generates JavaScript equivalent to the following:
var <EnumName>;
(function (<EnumName>) {
<EnumMemberAssignments>
})(<EnumName>||(<EnumName>={}));
EnumName is the name of the enum.
EnumMemberAssignments is a sequence of assignments, one for each enum member, in order they are declared, of the form
<EnumName>[<EnumName>["<MemberName>"] = <Value>] = "<MemberName>";
where MemberName is the name of the enum member and Value is the assigned constant value or the code generated for the computed value expression.
For example, the ‘Color’ enum example from section 9.1 generates the following JavaScript:
var Color;
(function (Color) {
Color[Color["Red"] = 0] = "Red";
Color[Color["Green"] = 1] = "Green";
Color[Color["Blue"] = 2] = "Blue";
})(Color||(Color={}));