const ColorEnum = {
RED: 'red',
GREEN: 'green',
BLUE: 'blue',
getValue(key) {
return this[key] || null;
}
}
使用 ColorEnum.getValue('RED')
、ColorEnum.getValue('GREEN')
和 ColorEnum.getValue('BLUE')
来获取对应的颜色值。如果传入的 key 不存在,则返回 null。