当前位置:网站首页>Ts——项目实战应用enum枚举
Ts——项目实战应用enum枚举
2022-08-04 21:58:00 【F班的小夏同学】
【基础介绍】
在这里我们只简单的回顾一下枚举的使用。
enum Direction {
Up = 1,
Down,
Left,
Right
}
如上,我们定义了一个数字枚举, Up使用初始化为 1。 其余的成员会从 1开始自动增长。 换句话说, Direction.Up的值为 1, Down为 2, Left为 3, Right为 4。
那么如何获取值呢?
console.log(Direction2.Down)//2
console.log(Direction2[2])//Down
假如我们不使用初始化器:
enum Direction {
Up,
Down,
Left,
Right,
}
现在, Up的值为 0, Down的值为 1等等。 当我们不在乎成员的值的时候,这种自增长的行为是很有用处的,但是要注意每个枚举成员的值都是不同的。
【在项目中使用】
在公共文件中列举出来状态枚举。
可以以对象的形式暴露出去
有时候还可以暴露一个公共符号
在你需要的页面引入公共文件
就可以使用了
边栏推荐
- AtCoder Beginner Contest 262 D - I Hate Non-integer Number
- [Linear Algebra 02] 2 interpretations of AX=b and 5 perspectives of matrix multiplication
- rk3399-9.0一级二级休眠
- openresty lua-resty-template页面静态化
- 【SQL之降龙十八掌】01——亢龙有悔:入门10题
- [Linear Algebra 03] Elimination method display and 4 solutions of AX=b
- Rt-thread [三] link.lds链接脚本详解
- docker 部署redis集群
- Yolov7:Trainable bag-of-freebies sets new state-of-the-art for real-time objectdetectors
- 《剑指offer》刷题分类
猜你喜欢

PMP证书在哪些行业有用?

rk3399-9.0 first-level and second-level dormancy

In action: 10 ways to implement delayed tasks, with code!

立方度量(Cubic Metric)

As hot as ever, reborn | ISC2022 HackingClub White Hat Summit was successfully held!

3D激光SLAM:LeGO-LOAM---两步优化的帧间里程计及代码分析

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd6 in position 120: invalid continuation byte

Debian防火墙的开关以及状态

ROS播包可视化

【CC3200AI 实验教程 1】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-开发环境搭建
随机推荐
PowerBI真经连续剧
2022年江苏省大学生电子设计竞赛(TI杯)B题 飞机 省级一等奖记录 “一个摆烂人的独白”
国际项目管理师PMP证书,值得考嘛?
rk3399-0.0 svc command
Domestic PMP certificate of gold content how
LeetCode: 406. 根据身高重建队列
【线性代数03】消元法展示以及AX=b的4种解情况
[Linear Algebra 02] 2 interpretations of AX=b and 5 perspectives of matrix multiplication
移动web开发03
如何为Web3.0世界启动完美的DAO
Rt-thread [二] 系统初始化流程
idea 仓库地址连接不上问题
Analysis and treatment of Ramnit infectious virus
unity2D横版游戏教程9-对话框dialog
Why is MySQL query slow?
C language knowledge (1) - overview of C language, data types
puzzle(022.1)黑白迭代
UDP communication
Ramnit感染型病毒分析与处置
com.jacob.com.ComFailException: Invoke of: ActiveDocument