编译前

    1. enum CompassDirection {
    2. North,
    3. East,
    4. South,
    5. West
    6. }
    7. const startingDirection = CompassDirection.East

    编译后,很巧妙的写法

    1. var CompassDirection;
    2. (function(CompassDirection) {
    3. CompassDirection[CompassDirection['North'] = 0] = 'North';
    4. CompassDirection[CompassDirection['East'] = 1] = 'East';
    5. CompassDirection[CompassDirection['South'] = 2] = 'South';
    6. CompassDirection[CompassDirection['West'] = 3] = 'West';
    7. })(CompassDirection || CompassDirection = {});
    8. const staringDirection = CompassDirection.East