枚举
Tutorial: TS初级一
Category: TS
Published: 2026-04-07 13:58:26
Views: 21
Likes: 0
Comments: 0
- 枚举举例
enum Direction {
Up,
Right,
Down,
Left,
}
enum Direction1 {
Up = 20,
Right,
Down,
Left = 80,
}
enum Direction2 {
Up = "UP",
Right = "RIGHT",
Down = "DOWN",
Left = "LEFT",
}
function changeDirection(dir: Direction) {
console.log(dir);
}
function changeDirection1(dir: Direction1) {
console.log(dir);
}
function changeDirection2(dir: Direction2) {
console.log(dir);
}
changeDirection(Direction.Down);
changeDirection1(Direction1.Down);
changeDirection1(Direction1.Left);
changeDirection2(Direction2.Left);