new Enum(name, values, options)
Constructs a new enum instance.
Name | Type | Description |
---|---|---|
name |
string |
Unique name within its namespace |
values |
Object.<string, number> |
optional
Enum values as an object, by name |
options |
Object.<string, *> |
optional
Declared options |
Extends
Members
-
comment { string | null }
-
Comment text, if any.
-
comments { Object<string, string> }
-
Value comment texts, if any.
-
filename { string | null }
-
Defining file name.
-
fullName readonly{ string }
-
Full name including leading dot.
-
name { string }
-
Unique name within its namespace.
-
options { Object<string, *> | undefined }
-
Options.
-
parent { Namespace | null }
-
Parent namespace.
-
reserved { (number[]|string)[] }
-
Reserved ranges, if any.
-
resolved { boolean }
-
Whether already resolved or not.
-
root readonly{ Root }
-
Reference to the root namespace.
-
values { Object<string, number> }
-
Enum values by name.
-
valuesById { Object<number, string> }
-
Enum values by id.
Methods
-
Enum.fromJSON(name, json){ Enum }
-
Constructs an enum from an enum descriptor.
Name Type Description name
string Enum name
json
IEnum Enum descriptor
Throws:
Type Description TypeError If arguments are invalid
Returns:
Type Description Enum Created enum -
add(name, id, comment){ Enum }
-
Adds a value to this enum.
Name Type Description name
string Value name
id
number Value id
comment
string optional Comment, if any
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description Error If there is already a value with this name or id
Returns:
Type Description Enum this
-
-
inherited getOption(name){ * }
-
Gets an option value.
Name Type Description name
string Option name
Returns:
Type Description * Option value or undefined
if not set -
isReservedId(id){ boolean }
-
Tests if the specified id is reserved.
Name Type Description id
number Id to test
Returns:
Type Description boolean true
if reserved, otherwisefalse
-
isReservedName(name){ boolean }
-
Tests if the specified name is reserved.
Name Type Description name
string Name to test
Returns:
Type Description boolean true
if reserved, otherwisefalse
-
inherited onAdd(parent){ undefined }
-
Called when this object is added to a parent.
Name Type Description parent
ReflectionObject Parent added to
Returns:
Type Description undefined -
inherited onRemove(parent){ undefined }
-
Called when this object is removed from a parent.
Name Type Description parent
ReflectionObject Parent removed from
Returns:
Type Description undefined -
remove(name){ Enum }
-
Removes a value from this enum
Name Type Description name
string Value name
Throws:
-
Type Description TypeError If arguments are invalid
-
Type Description Error If
name
is not a name of this enum
Returns:
Type Description Enum this
-
-
inherited resolve(){ ReflectionObject }
-
Resolves this objects type references.
Returns:
Type Description ReflectionObject this
-
inherited setOption(name, value, ifNotSet){ ReflectionObject }
-
Sets an option.
Name Type Description name
string Option name
value
* Option value
ifNotSet
boolean optional Sets the option only if it isn't currently set
Returns:
Type Description ReflectionObject this
-
inherited setOptions(options, ifNotSet){ ReflectionObject }
-
Sets multiple options.
Name Type Description options
Object.<string, *> Options to set
ifNotSet
boolean optional Sets an option only if it isn't currently set
Returns:
Type Description ReflectionObject this
-
toJSON(){ IEnum }
-
Converts this enum to an enum descriptor.
Returns:
Type Description IEnum Enum descriptor -
inherited toString(){ string }
-
Converts this instance to its string representation.
Returns:
Type Description string Class name[, space, full name]