diff --git a/js/model/ISLCModel.js b/js/model/ISLCModel.js index d72990d..d1f31cd 100644 --- a/js/model/ISLCModel.js +++ b/js/model/ISLCModel.js @@ -5,21 +5,21 @@ * * @author Jesse Greenberg (PhET Interactive Simulations) */ -define( function( require ) { +define( require => { 'use strict'; // modules - var BooleanProperty = require( 'AXON/BooleanProperty' ); - var DerivedProperty = require( 'AXON/DerivedProperty' ); - var DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); - var Emitter = require( 'AXON/Emitter' ); - var inherit = require( 'PHET_CORE/inherit' ); - var inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); - var ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); - var NumberIO = require( 'TANDEM/types/NumberIO' ); - var Property = require( 'AXON/Property' ); - var Range = require( 'DOT/Range' ); - var Util = require( 'DOT/Util' ); + const BooleanProperty = require( 'AXON/BooleanProperty' ); + const DerivedProperty = require( 'AXON/DerivedProperty' ); + const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); + const Emitter = require( 'AXON/Emitter' ); + const inherit = require( 'PHET_CORE/inherit' ); + const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); + const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); + const NumberIO = require( 'TANDEM/types/NumberIO' ); + const Property = require( 'AXON/Property' ); + const Range = require( 'DOT/Range' ); + const Util = require( 'DOT/Util' ); // constants const OBJECT_ONE = ISLCObjectEnum.OBJECT_ONE; @@ -37,8 +37,6 @@ define( function( require ) { */ function ISLCModel( forceConstant, object1, object2, locationRange, tandem, options ) { - var self = this; - options = _.extend( { snapObjectsToNearest: null, // {number|null} if defined, objects will snap to nearest value in model coordinates minSeparationBetweenObjects: 0.1 // in meters @@ -63,11 +61,7 @@ define( function( require ) { // @private this.snapObjectsToNearest = options.snapObjectsToNearest; - - // @private this.minSeparationBetweenObjects = options.minSeparationBetweenObjects; - - // @private this.forceConstant = forceConstant; // @public - emits an event when the model is updated by step @@ -80,44 +74,41 @@ define( function( require ) { this.object2.valueProperty, this.object1.positionProperty, this.object2.positionProperty - ], function( v1, v2, x1, x2 ) { - var distance = Math.abs( x2 - x1 ); - return self.calculateForce( v1, v2, distance ); - }, { + ], ( v1, v2, x1, x2 ) => this.calculateForce( v1, v2, Math.abs( x2 - x1 ) ), { phetioType: DerivedPropertyIO( NumberIO ), tandem: tandem.createTandem( 'forceProperty' ), units: 'newtons', phetioDocumentation: 'The force of one object on the other (in Newtons)' } ); - var updateRange = function( object ) { - var maxPosition = self.getObjectMaxPosition( object ); - var minPosition = self.getObjectMinPosition( object ); + const updateRange = object => { + const maxPosition = this.getObjectMaxPosition( object ); + const minPosition = this.getObjectMinPosition( object ); object.enabledRangeProperty.set( new Range( minPosition, maxPosition ) ); }; // a11y - necessary to reset the enabledRangeProperty to prevent object overlap, disposal not necessary // We need to update the available range for each object when the either's radius or position changes. - Property.multilink( [ object1.positionProperty, object2.positionProperty ], function() { + Property.multilink( [ object1.positionProperty, object2.positionProperty ], () => { updateRange( object1 ); updateRange( object2 ); } ); // when sim is reset, we only reset the position properties of each object to their initial values // thus, there is no need to dispose of the listeners below - this.object1.radiusProperty.link( function() { - self.object1.radiusLastChanged = true; - self.object2.radiusLastChanged = false; + this.object1.radiusProperty.link( () => { + this.object1.radiusLastChanged = true; + this.object2.radiusLastChanged = false; // update range if radius changed with "constant radius" setting (which didn't trigger other model updates) updateRange( object1 ); updateRange( object2 ); } ); - this.object2.radiusProperty.link( function() { - self.object2.radiusLastChanged = true; - self.object1.radiusLastChanged = false; + this.object2.radiusProperty.link( () => { + this.object2.radiusLastChanged = true; + this.object1.radiusLastChanged = false; // update range if radius changed with "constant radius" setting (which didn't trigger other model updates) updateRange( object2 ); @@ -134,7 +125,7 @@ define( function( require ) { // This conditional should only be hit if the mass has changed in addition to the position. Since the object's // valueProperty would be set in the previous frame, and then this frame's step function would update the - // position. This was understood to be the truth by @zepumph while working on https://github.com/phetsims/gravity-force-lab-basics/issues/132 + // position. this.pushedObjectEnumProperty.value = objectEnum; } }; @@ -164,19 +155,19 @@ define( function( require ) { * @public */ step: function() { - var minX = this.leftObjectBoundary; - var maxX = this.rightObjectBoundary; + const minX = this.leftObjectBoundary; + const maxX = this.rightObjectBoundary; - var locationObject1 = this.object1.positionProperty.get(); - var locationObject2 = this.object2.positionProperty.get(); + let locationObject1 = this.object1.positionProperty.get(); + let locationObject2 = this.object2.positionProperty.get(); // bounds for the left object are the left boundary and the right edge of object 2 minus half the min separation - var minPositionObject1 = minX; - var maxPositionObject1 = this.getObjectMaxPosition( this.object1 ); + const minPositionObject1 = minX; + const maxPositionObject1 = this.getObjectMaxPosition( this.object1 ); // bounds for the right object are the right edge of object 1 plus half the separation distance and the right edge - var minPositionObject2 = this.getObjectMinPosition( this.object2 ); - var maxPositionObject2 = maxX; + const minPositionObject2 = this.getObjectMinPosition( this.object2 ); + const maxPositionObject2 = maxX; // make sure that the objects don't go beyond the boundaries locationObject1 = Math.max( minPositionObject1, locationObject1 ); @@ -251,17 +242,16 @@ define( function( require ) { /** * Helper function to for accessing and mapping force ranges in the inheriting sims' views * - * Note: this function assumes that the ranges of both objects' values are the same - * * @public * @returns {number} the smallest possible force magnitude */ getMinForce: function() { - var maxDistance = Math.abs( this.rightObjectBoundary - this.leftObjectBoundary ); + this.assertObjectsHaveSameRange(); + const maxDistance = Math.abs( this.rightObjectBoundary - this.leftObjectBoundary ); // Since we're checking for magnitude, negative values for charges will need // to be set to zero. - var minValue = this.object1.valueRange.min < 0 ? 0 : this.object1.valueRange.min; + const minValue = this.object1.valueRange.min < 0 ? 0 : this.object1.valueRange.min; // ensure we always return a positive force value or zero return Math.abs( this.calculateForce( minValue, minValue, maxDistance ) ); @@ -270,16 +260,25 @@ define( function( require ) { /** * Helper function to for accessing and mapping force ranges in the inheriting sims' views * - * Note: this function assumes that the ranges of both objects' values are the same - * * @public * @returns {number} the largest possible force magnitude */ getMaxForce: function() { - var maxValue = this.object1.valueRange.max; + this.assertObjectsHaveSameRange(); + + const maxValue = this.object1.valueRange.max; return Math.abs( this.calculateForce( maxValue, maxValue, this.getMinDistance( maxValue ) ) ); }, + /** + * Multiple functions in the model need to assume this, so these assertions are factored out. + * @private + */ + assertObjectsHaveSameRange: function() { + assert && assert( this.object1.valueProperty.range.min === this.object2.valueProperty.range.min, 'range min should be the same' ); + assert && assert( this.object1.valueProperty.range.max === this.object2.valueProperty.range.max, 'range max should be the same' ); + }, + /** * Get the minimum possible separation between the objects' centers given a defined value for each of their * main properties. @@ -291,7 +290,7 @@ define( function( require ) { getMinDistance: function( value ) { // calculate radius for masses and charges at maximum mass/charge - var minRadius = this.object1.calculateRadius( value ); + const minRadius = this.object1.calculateRadius( value ); return ( 2 * minRadius ) + this.minSeparationBetweenObjects; }, @@ -317,9 +316,10 @@ define( function( require ) { * @returns {number} */ getSumRadiusWithSeparation: function() { - return this.snapToGrid( - this.object1.radiusProperty.get() + this.object2.radiusProperty.get() + this.minSeparationBetweenObjects - ); + const distanceSum = this.object1.radiusProperty.get() + + this.object2.radiusProperty.get() + + this.minSeparationBetweenObjects; + return this.snapToGrid( distanceSum ); }, /** @@ -331,8 +331,8 @@ define( function( require ) { */ getObjectMaxPosition: function( object ) { - var sumRadius = this.getSumRadiusWithSeparation(); - var maxX; + const sumRadius = this.getSumRadiusWithSeparation(); + let maxX; if ( object === this.object1 ) { // the max value for the left object is the position of the right object minius the sum of radii @@ -356,8 +356,8 @@ define( function( require ) { */ getObjectMinPosition: function( object ) { - var sumRadius = this.getSumRadiusWithSeparation(); - var minX; + const sumRadius = this.getSumRadiusWithSeparation(); + let minX; if ( object === this.object1 ) { // the min value for the left object is the left edge plus the puller width and the radius of the object @@ -389,8 +389,8 @@ define( function( require ) { * @returns {number} */ snapToGrid: function( position ) { - var snappedPosition = position; - var numDecimalPlaces = Util.numberOfDecimalPlaces( this.snapObjectsToNearest ); + let snappedPosition = position; + const numDecimalPlaces = Util.numberOfDecimalPlaces( this.snapObjectsToNearest ); if ( this.snapObjectsToNearest ) { snappedPosition = Util.roundSymmetric( position / this.snapObjectsToNearest ) * this.snapObjectsToNearest; snappedPosition = Util.toFixedNumber( snappedPosition, numDecimalPlaces ); diff --git a/js/model/ISLCObject.js b/js/model/ISLCObject.js index a405120..3f95787 100644 --- a/js/model/ISLCObject.js +++ b/js/model/ISLCObject.js @@ -5,22 +5,22 @@ * * @author Jesse Greenberg (PhET Interactive Simulations) */ -define( function( require ) { +define( require => { 'use strict'; // modules - var DerivedProperty = require( 'AXON/DerivedProperty' ); - var DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); - var Emitter = require( 'AXON/Emitter' ); - var inherit = require( 'PHET_CORE/inherit' ); - var inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); - var ISLCConstants = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCConstants' ); - var NumberIO = require( 'TANDEM/types/NumberIO' ); - var NumberProperty = require( 'AXON/NumberProperty' ); - var Property = require( 'AXON/Property' ); - var PropertyIO = require( 'AXON/PropertyIO' ); - var Range = require( 'DOT/Range' ); - var RangeIO = require( 'DOT/RangeIO' ); + const DerivedProperty = require( 'AXON/DerivedProperty' ); + const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' ); + const Emitter = require( 'AXON/Emitter' ); + const inherit = require( 'PHET_CORE/inherit' ); + const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); + const ISLCConstants = require( 'INVERSE_SQUARE_LAW_COMMON/ISLCConstants' ); + const NumberIO = require( 'TANDEM/types/NumberIO' ); + const NumberProperty = require( 'AXON/NumberProperty' ); + const Property = require( 'AXON/Property' ); + const PropertyIO = require( 'AXON/PropertyIO' ); + const Range = require( 'DOT/Range' ); + const RangeIO = require( 'DOT/RangeIO' ); /** * @param {number} initialMass @@ -33,8 +33,6 @@ define( function( require ) { */ function ISLCObject( initialMass, initialPosition, valueRange, constantRadiusProperty, tandem, options ) { - var self = this; - options = _.extend( { // in meters @@ -60,8 +58,8 @@ define( function( require ) { // @public {Property.} - the radius of the mass or charge in meters // since ISLCObjects are never destroyed, no need to dispose this.radiusProperty = new DerivedProperty( [ this.valueProperty, constantRadiusProperty ], - function( valueProperty, constantRadius ) { - return constantRadius ? options.constantRadius : self.calculateRadius( valueProperty ); + ( valueProperty, constantRadius ) => { + return constantRadius ? options.constantRadius : this.calculateRadius( valueProperty ); }, { tandem: tandem.createTandem( 'radiusProperty' ), units: 'meters', @@ -69,7 +67,7 @@ define( function( require ) { } ); - var enabledRange = new Range( options.leftObjectBoundary, options.rightObjectBoundary ); + const enabledRange = new Range( options.leftObjectBoundary, options.rightObjectBoundary ); // @public {Property.}- set by ISLCModel when the force changes this.enabledRangeProperty = new Property( enabledRange, { diff --git a/js/view/ISLCObjectNode.js b/js/view/ISLCObjectNode.js index 0cef1af..56c61de 100644 --- a/js/view/ISLCObjectNode.js +++ b/js/view/ISLCObjectNode.js @@ -10,36 +10,34 @@ * @author Michael Barlow (PhET Interactive Simulations) * @author Jesse Greenberg (PhET Interactive Simulations) */ -define( function( require ) { +define( require => { 'use strict'; // modules - var AccessibleSlider = require( 'SUN/accessibility/AccessibleSlider' ); - var Color = require( 'SCENERY/util/Color' ); - var Circle = require( 'SCENERY/nodes/Circle' ); - var inherit = require( 'PHET_CORE/inherit' ); - var inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); - var ISLCAlertManager = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCAlertManager' ); - var ISLCForceArrowNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCForceArrowNode' ); - var ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); - var ISLCPullerNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCPullerNode' ); - var Node = require( 'SCENERY/nodes/Node' ); - var Path = require( 'SCENERY/nodes/Path' ); - var PhetFont = require( 'SCENERY_PHET/PhetFont' ); - var PositionDescriber = require( 'INVERSE_SQUARE_LAW_COMMON/view/describers/PositionDescriber' ); - var Range = require( 'DOT/Range' ); - var RichText = require( 'SCENERY/nodes/RichText' ); - var Shape = require( 'KITE/Shape' ); - var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' ); - var Tandem = require( 'TANDEM/Tandem' ); - var Util = require( 'DOT/Util' ); - - // phetio - var BooleanProperty = require( 'AXON/BooleanProperty' ); + const AccessibleSlider = require( 'SUN/accessibility/AccessibleSlider' ); + const BooleanProperty = require( 'AXON/BooleanProperty' ); + const Color = require( 'SCENERY/util/Color' ); + const Circle = require( 'SCENERY/nodes/Circle' ); + const inherit = require( 'PHET_CORE/inherit' ); + const inverseSquareLawCommon = require( 'INVERSE_SQUARE_LAW_COMMON/inverseSquareLawCommon' ); + const ISLCAlertManager = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCAlertManager' ); + const ISLCForceArrowNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCForceArrowNode' ); + const ISLCObjectEnum = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCObjectEnum' ); + const ISLCPullerNode = require( 'INVERSE_SQUARE_LAW_COMMON/view/ISLCPullerNode' ); + const Node = require( 'SCENERY/nodes/Node' ); + const Path = require( 'SCENERY/nodes/Path' ); + const PhetFont = require( 'SCENERY_PHET/PhetFont' ); + const PositionDescriber = require( 'INVERSE_SQUARE_LAW_COMMON/view/describers/PositionDescriber' ); + const Range = require( 'DOT/Range' ); + const RichText = require( 'SCENERY/nodes/RichText' ); + const Shape = require( 'KITE/Shape' ); + const SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' ); + const Tandem = require( 'TANDEM/Tandem' ); + const Util = require( 'DOT/Util' ); // constants - var LABEL_MAX_WIDTH = 20; // empirically determined through testing with long strings - var ARROW_OPTION_KEYS = [ + const LABEL_MAX_WIDTH = 20; // empirically determined through testing with long strings + const ARROW_OPTION_KEYS = [ 'defaultDirection', 'attractNegative', // if true, arrows will point towards each other if forces is negative 'arrowNodeLineWidth', @@ -63,7 +61,7 @@ define( function( require ) { 'arrowStroke', 'arrowFill' ]; - var PULLER_OPTION_KEYS = [ + const PULLER_OPTION_KEYS = [ 'ropeLength', 'shadowMinWidth', 'shadowMaxWidth', @@ -72,9 +70,9 @@ define( function( require ) { 'atomicScale' ]; - var NEGATIVE_FILL = new Color( '#66f' ); - var POSITIVE_FILL = new Color( '#f66' ); - var ZERO_FILL = new Color( 'gray' ); + const NEGATIVE_FILL = new Color( '#66f' ); + const POSITIVE_FILL = new Color( '#f66' ); + const ZERO_FILL = new Color( 'gray' ); /** * @param {ISLCModel} model - the simulation model @@ -89,8 +87,6 @@ define( function( require ) { */ function ISLCObjectNode( model, object, layoutBounds, modelViewTransform, alertManager, positionDescriber, options ) { - var self = this; - options = _.extend( { label: 'This Object', otherObjectLabel: 'Other Object', @@ -131,7 +127,7 @@ define( function( require ) { additionalA11yDependencies: [] }, options ); - var tandem = options.tandem; + const tandem = options.tandem; // use snapToNearest if stepSize is not provided if ( options.stepSize === null ) { @@ -162,7 +158,7 @@ define( function( require ) { this.enum = object === model.object1 ? ISLCObjectEnum.OBJECT_ONE : ISLCObjectEnum.OBJECT_TWO; // the full range of force for the arrow node (note: this is distinct) - var arrowForceRange = new Range( model.getMinForce(), model.getMaxForce() ); + const arrowForceRange = new Range( model.getMinForce(), model.getMaxForce() ); // @protected - arrow node this.arrowNode = new ISLCForceArrowNode( @@ -176,7 +172,6 @@ define( function( require ) { // set y position for the arrow this.arrowNode.y = options.y - options.forceArrowHeight; - // @private - the puller node this.pullerNode = new ISLCPullerNode( pullForceRange, @@ -189,13 +184,13 @@ define( function( require ) { } // a parent node that applies the drag handler - var dragNode = new Node( { + const dragNode = new Node( { cursor: 'pointer', tandem: tandem.createTandem( 'dragNode' ) } ); // the 'object' - a shaded circle - var radius = modelViewTransform.modelToViewDeltaX( object.radiusProperty.get() ); + const radius = modelViewTransform.modelToViewDeltaX( object.radiusProperty.get() ); // @protected - the object this.objectCircle = new Circle( radius ); @@ -206,8 +201,8 @@ define( function( require ) { // Small black dot where vertical arrow line connects to the object dragNode.addChild( new Circle( 2, { fill: '#000' } ) ); - var labelCenterX = 0; - var labelTop = 4; + const labelCenterX = 0; + const labelTop = 4; // add the label shadow, added first so that the 'shadow' appears under the label text dragNode.addChild( new RichText( options.label, { @@ -238,7 +233,7 @@ define( function( require ) { // the marker line, connecting the arrow to the object, the first one is for the shadow so that // it is visible on top of the object - var markerLineShape = new Shape(); + const markerLineShape = new Shape(); markerLineShape.moveTo( 0, -4 ); markerLineShape.lineTo( 0, -options.forceArrowHeight ); this.addChild( new Path( markerLineShape, { @@ -249,7 +244,7 @@ define( function( require ) { y: 0.5, tandem: tandem.createTandem( 'markerLineShadow' ) } ) ); - var markerLineShapeTop = new Path( markerLineShape, { + const markerLineShapeTop = new Path( markerLineShape, { stroke: options.arrowColor, lineDash: [ 4, 4 ], lineWidth: 2, @@ -257,23 +252,23 @@ define( function( require ) { } ); this.addChild( markerLineShapeTop ); - var clickOffset; + let clickOffset; dragNode.addInputListener( new SimpleDragHandler( { allowTouchSnag: true, - start: function( event ) { + start: event => { clickOffset = dragNode.globalToParentPoint( event.pointer.point ).x - event.currentTarget.x; object.isDragging = true; }, - drag: function( event ) { + drag: event => { // drag position relative to the pointer pointer start position and convert to model coordinates - var x = modelViewTransform.viewToModelX( self.globalToParentPoint( event.pointer.point ).x - clickOffset ); + let x = modelViewTransform.viewToModelX( this.globalToParentPoint( event.pointer.point ).x - clickOffset ); // absolute drag bounds based on model // see method descriptions for details - var xMax = model.getObjectMaxPosition( object ); - var xMin = model.getObjectMinPosition( object ); + const xMax = model.getObjectMaxPosition( object ); + const xMin = model.getObjectMinPosition( object ); // apply limitations and update position x = Math.max( Math.min( x, xMax ), xMin ); // limited value of x (by boundary) in model coordinates @@ -281,21 +276,18 @@ define( function( require ) { // snapToGrid method dynamically checks whether to snap or not object.positionProperty.set( model.snapToGrid( x ) ); }, - end: function( event ) { - object.isDragging = false; - // position change alert - // TODO: Do we activate alerts for mouse interactions? - }, + end: () => { object.isDragging = false }, tandem: tandem.createTandem( 'dragHandler' ) } ) ); - model.forceValuesProperty.lazyLink( this.redrawForce.bind( this ) ); - object.radiusProperty.lazyLink( this.redrawForce.bind( this ) ); - object.valueProperty.lazyLink( this.redrawForce.bind( this ) ); - model.forceProperty.lazyLink( this.redrawForce.bind( this ) ); + const boundRedrawForce = this.redrawForce.bind( this ); + model.forceValuesProperty.lazyLink( boundRedrawForce ); + object.radiusProperty.lazyLink( boundRedrawForce ); + object.valueProperty.lazyLink( boundRedrawForce ); + model.forceProperty.lazyLink( boundRedrawForce ); - object.baseColorProperty.link( function( baseColor ) { - self.updateGradient( baseColor ); + object.baseColorProperty.link( baseColor => { + this.updateGradient( baseColor ); if ( options.attractNegative ) { markerLineShapeTop.stroke = getUpdatedFill( object.valueProperty.get() ); } @@ -303,42 +295,36 @@ define( function( require ) { // on reset, no objects are destroyed and properties are set to initial values // no need to dispose of any of the below listeners - object.positionProperty.link( function( property ) { + object.positionProperty.link( property => { // position this node and its force arrow with label - var transformedValue = modelViewTransform.modelToViewX( property ); - self.x = transformedValue; - self.arrowNode.x = transformedValue; - self.redrawForce(); + const transformedValue = modelViewTransform.modelToViewX( property ); + this.x = transformedValue; + this.arrowNode.x = transformedValue; + this.redrawForce(); } ); - var oldPosition = object.positionProperty.get(); - var accessibleSliderOptions = { + let oldPosition = object.positionProperty.get(); + const accessibleSliderOptions = { keyboardStep: options.stepSize, shiftKeyboardStep: options.snapToNearest, pageKeyboardStep: options.stepSize * 2, a11yDecimalPlaces: 1, - constrainValue: function( value ) { - var numberOfDecimalPlaces = Util.numberOfDecimalPlaces( options.snapToNearest ); + constrainValue: value => { + const numberOfDecimalPlaces = Util.numberOfDecimalPlaces( options.snapToNearest ); return Util.toFixedNumber( value, numberOfDecimalPlaces ); }, - startDrag: function() { + startDrag: () => { object.isDragging = true; oldPosition = object.positionProperty.get(); }, - endDrag: function() { - var newPosition = object.positionProperty.get(); - var positionChanged = newPosition !== oldPosition; + endDrag: () => { + const newPosition = object.positionProperty.get(); + const positionChanged = newPosition !== oldPosition; object.isDragging = false; - self.redrawForce(); + this.redrawForce(); - // TODO: these alerts should occur on mouse as well - if ( positionChanged ) { - alertManager.alertPositionChanged( object ); - } - else { - alertManager.alertPositionUnchanged(); - } + positionChanged ? alertManager.alertPositionChanged( object ) : alertManager.alertPositionUnchanged(); }, a11yCreateValueChangeAriaValueText: positionDescriber.getOnChangeAriaValueTextCreator( this.enum ), @@ -357,22 +343,22 @@ define( function( require ) { ); // TODO: move to MassNode since ChargeNodes don't have a changing radiusProperty. - this.objectModel.radiusProperty.link( function() { + this.objectModel.radiusProperty.link( () => { // a11y - update the focusHighlight with the radius (Accessibility.js setter) - self.focusHighlight = Shape.bounds( dragNode.bounds.dilated( 5 ) ); + this.focusHighlight = Shape.bounds( dragNode.bounds.dilated( 5 ) ); // set the pointer and touch areas - var pullerBounds = self.pullerNode.localToParentBounds( self.pullerNode.touchAreaBounds ); - self.mouseArea = Shape.xor( [ Shape.bounds( pullerBounds ), self.objectCircle.createCircleShape() ] ); - self.touchArea = self.mouseArea; + const pullerBounds = this.pullerNode.localToParentBounds( this.pullerNode.touchAreaBounds ); + this.mouseArea = Shape.xor( [ Shape.bounds( pullerBounds ), this.objectCircle.createCircleShape() ] ); + this.touchArea = this.mouseArea; } ); // for layering purposes, we assume that the ScreenView will add the arrow node and label - by the // time the sim is stepped, make sure that the arrows are added to the view if ( assert ) { - var checkForArrowAdded = function() { - if ( self.arrowNode.parents.length === 0 ) { + const checkForArrowAdded = () => { + if ( this.arrowNode.parents.length === 0 ) { throw new Error( 'ArrowNode should be added to the view in inverse-square-law-common sim screen view' ); } @@ -391,7 +377,7 @@ define( function( require ) { */ function getUpdatedFill( forceValue ) { - var fill; + let fill; if ( forceValue < 0 ) { fill = NEGATIVE_FILL; }