Skip to content

EnumerationValue

Overview

EnumerationValue is the base class for enumeration value instances. See https://github.com/phetsims/phet-info/blob/main/doc/phet-software-design-patterns.md#enumeration

PhET's Enumeration pattern is:

class MyEnumeration extends EnumerationValue { public static readonly VALUE_1 = new MyEnumeration(); public static readonly VALUE_2 = new MyEnumeration();

// Make sure this is last, once all EnumerationValues have been declared statically. public static readonly enumeration = new Enumeration( MyEnumeration ); }

// Usage console.log( MyEnumeration.VALUE_1 ); const printValue = enumValue => { affirm( enumValue.enumeration.values.includes(enumValue)); console.log( enumValue ); }; printValue( MyEnumeration.VALUE_2 );

@author Sam Reid (PhET Interactive Simulations) @author Michael Kauzmann (PhET Interactive Simulations)

Class EnumerationValue

import { EnumerationValue } from 'scenerystack/phet-core';

Constructor

new EnumerationValue()

Instance Methods

toString() : string

Static Properties

sealedCache : Set

After an Enumeration is constructed, no new instances of that exact type can be made (though it is OK to create subtypes)

Source Code

See the source for EnumerationValue.ts in the phet-core repository.