Skip to content

Instantly share code, notes, and snippets.

@YanceyOfficial
Created May 15, 2019 08:10
Show Gist options
  • Save YanceyOfficial/6e5d858d5eff750356f24160ed30692c to your computer and use it in GitHub Desktop.
Save YanceyOfficial/6e5d858d5eff750356f24160ed30692c to your computer and use it in GitHub Desktop.
babel-enum
enum Direction {
  Up = 1,
  Down,
  Left,
  Right
}
// 编译后
var Direction;
(function(Direction) {
  Direction[(Direction['Up'] = 1)] = 'Up';
  Direction[(Direction['Down'] = 2)] = 'Down';
  Direction[(Direction['Left'] = 3)] = 'Left';
  Direction[(Direction['Right'] = 4)] = 'Right';
})(Direction || (Direction = {}));
// 结果
{ '1': 'Up',
  '2': 'Down',
  '3': 'Left',
  '4': 'Right',
  Up: 1,
  Down: 2,
  Left: 3,
  Right: 4 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment