js enums class

Solutions on MaxInterview for js enums class by the best coders in the world

showing results for - "js enums class"
Melvin
13 Feb 2019
1class Enum {
2  constructor(...keys) {
3    keys.forEach((key, i) => {
4      this[key] = i;
5    });
6    Object.freeze(this);
7  }
8
9  *[Symbol.iterator]() {
10    for (let key of Object.keys(this)) yield key;
11  }
12}
13
14const daysEnum = new Enum(
15  'monday',
16  'tuesday',
17  'wednesday',
18  'thursday',
19  'friday',
20  'saturday',
21  'sunday'
22);
23
24const days = [...daysEnum]; // Array of the enum values as strings