new Enum(values)
An Enum helper class that allows the user of many various setting methods
An Enum constructor can take many different types to construct an Enum from:
- String
- Comma-Delimited String
- Object
- Array
- Array of Objects
- Array of Strings
- Array of Arrays of Object
- etc.
Once created an Enum is immutable.
Enums inherit from the Serializable class so it also has:
toObject()toJSON()
Parameters:
| Name | Type | Description |
|---|---|---|
values |
Object
|
Array.<(Object|String)>
|
String
|
Throws:
UnsupportedError
Example
const states = new Enum([
'OPEN',
'IN_PROGRESS',
'CLOSED'
]);
console.info(states.OPEN) // 'OPEN'
states.DONE = 'DONE'
console.info(states.DONE) // undefined
const other_states = new Enum({
'START': 'START',
'IN_PROGRESS': 'IN_PROGRESS',
'DONE': 'DONE'
})
console.info(other_states.START) // 'START'
other_states.DONE = 'DONE';
console.info(other_states.DONE) // undefined