I need help. I want to implement Enum with modern javascript. I want it to be immutable and think that it will look something like this:
class AlphabetEnum{
static get A(){
return 'a';
},
static get B(){
return 'b';
}
...
}
However, it is a little annoying to write all these getters. Therefore, I am wondering if it is possible to optimize this using the names of the calculation methods and, possibly, some other es2015 functions.
As a result, I dream of having something like this:
let alph = [a, b, c, ..., z];
class AlphabetEnum{
static get [some__clever_way_to_resolve_names_from_<alph>](){
return some_clever_way_to_understand_what's_called();
},
}
source
share