上QQ阅读APP看书,第一时间看更新
Const enums
A slight variant of the enum type is the const enum, which simply adds the keyword const before the enum definition, as follows:
const enum DoorStateConst { Open, Closed, Ajar } var constDoorOpen = DoorStateConst.Open; console.log(`constDoorOpen is : ${constDoorOpen}`);
const enums have been introduced largely for performance reasons. Let's take a quick look at the JavaScript that is generated from this DoorStateConst enum:
var constDoorOpen = 0 /* Open */;
Note how the compiler has simply resolved the DoorStateConst.Open enum to its internal value of 0, and removed the const enum definition entirely.