当前位置:网站首页>How to define an "enumeration" type in JS
How to define an "enumeration" type in JS
2022-06-23 21:02:00 【User 1349575】
Javascript1.8.5 You can use Object.freeze To freeze objects to implement a similar ” enumeration ” type .
The implementation code is as follows :
/**
* Time :2019 year 8 month 18 Japan
* Front end tutorial : https://www.pipipi.net/
*/
var DaysEnum = Object.freeze({"monday":1, "tuesday":2, "wednesday":3, ...})Or so :
/**
* Time :2019 year 8 month 18 Japan
* Front end tutorial : https://www.pipipi.net/
*/
var DaysEnum = {"monday":1, "tuesday":2, "wednesday":3, ...}
Object.freeze(DaysEnum)This is it. js Medium ” enumeration ”! Is it simple ?
But now it's 2019 Years. , We can also use const To define the object .
Complete code
The complete implementation code is as follows :
/**
* Time :2019 year 8 month 18 Japan
* Front end tutorial : https://www.pipipi.net/
*/
var Status = Object.freeze({
"Connecting":0,
"Ready":1,
"Loading":2,
"Processing": 3
});
console.log(Status.Ready) // 1
console.log(Object.keys(Status)[Status.Ready]) // Ready边栏推荐
- . NET Core . NET Framework
- Use of the vs2022scanf function. An error is reported when using scanf - the return value is ignored: Solutions
- Can Tencent cloud disk service share data? What are the advantages of cloud disk service?
- How to check whether the service is running normally after easydss cluster transcoding is set up?
- Full instructions for databinding
- Encryption and decryption analysis of returned data of an e-commerce app (IV)
- From different angles, you can learn about the implementation of sliding list in fluent
- Digital procurement transformation solution: SaaS procurement management platform promotes enterprise sunshine procurement
- JS regular ignore case
- Copilot - employee, your layoff notice has been delivered
猜你喜欢

FPGA based electromagnetic ultrasonic pulse compression detection system paper + source file
Application of JDBC in performance test

Yaokui tower in Fengjie, Chongqing, after its completion, will be the safety tower for Sichuan river shipping with five local scholars in the company
Implementing MySQL fuzzy search with node and express

3000 frame animation illustrating why MySQL needs binlog, redo log and undo log

Use of the vs2022scanf function. An error is reported when using scanf - the return value is ignored: Solutions

JS advanced programming version 4: generator learning

Applet development framework recommendation
随机推荐
[golang] use go language to operate etcd - configuration center
Postman tutorial - teach you API interface testing by hand
How is the picture mosaic clear? What is mosaic for?
Configure two databases in master-slave database mode (master and slave)
Newbeecoder. UI new open source control library DataGrid instructions
Machine learning related
Bypass memory integrity check
Troubleshooting of black screen after easynvr is cascaded to the upper platform and played for one minute
国内期货开户怎么开?哪家期货公司开户更安全?
What is the process of setting up local cloud on demand? Can cloud on demand audit videos?
【Golang】快速复习指南QuickReview(八)——goroutine
How PostgreSQL quickly locate blocking SQL
Can Tencent cloud disk service share data? What are the advantages of cloud disk service?
From different angles, you can learn about the implementation of sliding list in fluent
ASP. Net MVC and asp Net web form
Sharelist supports simultaneous mounting of Google drive/onedrive multiple network disks
How do I close and restore ports 135, 139 and 445?
Command line add user set password never expires add remote group add administrator group
How to check whether the service is running normally after easydss cluster transcoding is set up?
【Golang】来几道题以加强Slice