cases
I've a enum object with many constants specified.
And have a switch case for fields in the enum, as well as others.
Now, i want the user to give custom names for the fields in enum + others, w/o altering the enum
And i generate an object with keys as original names, and values as the custom names if any, if no custom field, then the value would be null.
Now the confusing part is, how to do switch case with the new values, ?
* as this is a switch, it can easily avoid other fields, so i just need to replace existing switch case if there are custom fields for that case.
Use a map instead of a switch switch (something) { case "a": ... case "b": ... default: default(); } can be written const cases = new Map([ ["a", ...], ["b", ...] ]) const result = cases.get(something) ?? default();
Обсуждают сегодня