phetsims / phet-core

Core utilities used by all PhET simulations.
MIT License
8 stars 6 forks source link

Enumeration should fail when we attempt to overwrite values #45

Closed samreid closed 5 years ago

samreid commented 5 years ago

In #42 @pixelzoom said:

  • [ ] Enumeration silently ignores assignment attempts. E.g.
> Animal.COW = 'dog'
"dog"
> Animal.COW
"cow"

The assignment above should be an error.

samreid commented 5 years ago

@jonathanolson said:

This doesn't happen in strict mode, which we use. It throws a type error

samreid commented 5 years ago

I tested that in strict mode, Enumeration cannot assign values. I tried:

CardinalDirection.WEST=CardinalDirection.EAST;

and received:

Cannot assign to read only property 'WEST' of object '#'

I also noted this is covered in the Enumeration unit tests:

    window.assert && assert.throws( function() {
      E.SOMETHING_AFTER_THE_FREEZE = 5;
    }, 'Should not be able to set things after initialization' );

@pixelzoom can this issue be closed?