phetsims / bending-light

"Bending Light" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/bending-light
GNU General Public License v3.0
8 stars 8 forks source link

instances are created before Substance type is fully defined #349

Closed pixelzoom closed 8 years ago

pixelzoom commented 8 years ago

Problem in Substance:

  return inherit( Object, Substance, {}, {
    AIR: new Substance( airString, 1.000293, false, false ),
    WATER: new Substance( waterString, 1.333, false, false ),
    GLASS: new Substance( glassString, 1.5, false, false ),
    DIAMOND: new Substance( diamondString, DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT, false, false ),
    MYSTERY_A: new Substance( mysteryAString, DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT, true, false ),
    MYSTERY_B: new Substance( mysteryBString, 1.4, true, false ),
    DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT: DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT
  } )

The static instances are created before inherit is called, so instanceof tests will fail. See https://github.com/phetsims/phet-core/issues/24.

The fix is to create the instances after the inherit call:

inherit( Object, Substance, {}, {
  DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT: DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT
} );

Substance.AIR = new Substance( airString, 1.000293, false, false );
Substance.WATER = new Substance( waterString, 1.333, false, false );
Substance .GLASS = new Substance( glassString, 1.5, false, false );
Substance.DIAMOND = new Substance( diamondString, DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT, false, false );
Substance.MYSTERY_A = new Substance( mysteryAString, DIAMOND_INDEX_OF_REFRACTION_FOR_RED_LIGHT, true, false );
Substance .MYSTERY_B = new Substance( mysteryBString, 1.4, true, false );

return Substance;
pixelzoom commented 8 years ago

Fix described above committed and pushed. Assigned to @samreid for review.

samreid commented 8 years ago

The change set looks great, thanks @pixelzoom, closing.