diff --git a/js/Action.js b/js/Action.js index 31f9e993..3bdd188a 100644 --- a/js/Action.js +++ b/js/Action.js @@ -195,7 +195,7 @@ define( require => { */ static getPhetioDocumentation( currentPhetioDocumentation, parameters ) { const paramToDocString = param => { - var docText = param.phetioDocumentation && !_.endsWith( param.phetioDocumentation, '.' ) ? '. ' + param.phetioDocumentation : ''; + const docText = param.phetioDocumentation && !_.endsWith( param.phetioDocumentation, '.' ) ? '. ' + param.phetioDocumentation : ''; return `
  • ${param.name}: ${param.phetioType.typeName}${docText}
  • `; }; diff --git a/js/BooleanPropertyTests.js b/js/BooleanPropertyTests.js index 4f86211f..32acee0d 100644 --- a/js/BooleanPropertyTests.js +++ b/js/BooleanPropertyTests.js @@ -16,7 +16,7 @@ define( require => { QUnit.module( 'BooleanProperty' ); QUnit.test( 'BooleanProperty', function( assert ) { - var p = null; + let p = null; // isValidValue window.assert && assert.throws( function() { diff --git a/js/DerivedPropertyTests.js b/js/DerivedPropertyTests.js index 0c984ce5..2b506e20 100644 --- a/js/DerivedPropertyTests.js +++ b/js/DerivedPropertyTests.js @@ -15,20 +15,20 @@ define( require => { QUnit.module( 'DerivedProperty' ); QUnit.test( 'Test stale values in DerivedProperty', function( assert ) { - var a = new Property( 1 ); - var b = new Property( 2 ); - var c = new DerivedProperty( [ a, b ], function( a, b ) {return a + b;} ); + const a = new Property( 1 ); + const b = new Property( 2 ); + const c = new DerivedProperty( [ a, b ], function( a, b ) {return a + b;} ); a.value = 7; assert.equal( c.value, 9 ); } ); QUnit.test( 'Test DerivedProperty.unlink', function( assert ) { - var widthProperty = new Property( 2 ); - var heightProperty = new Property( 3 ); - var areaProperty = new DerivedProperty( [ widthProperty, heightProperty ], + const widthProperty = new Property( 2 ); + const heightProperty = new Property( 3 ); + const areaProperty = new DerivedProperty( [ widthProperty, heightProperty ], function( width, height ) { return width * height; } ); - var listener = function( area ) { /*console.log( 'area = ' + area );*/ }; + const listener = function( area ) { /*console.log( 'area = ' + area );*/ }; areaProperty.link( listener ); assert.equal( widthProperty.changedEmitter.getListenerCount(), 1 ); @@ -52,9 +52,9 @@ define( require => { QUnit.test( 'DerivedProperty.valueEquals', function( assert ) { - var propA = new Property( 'a' ); - var propB = new Property( 'b' ); - var prop = DerivedProperty.valueEquals( propA, propB ); + const propA = new Property( 'a' ); + const propB = new Property( 'b' ); + const prop = DerivedProperty.valueEquals( propA, propB ); assert.equal( prop.value, false ); propA.value = 'b'; assert.equal( prop.value, true ); @@ -62,10 +62,10 @@ define( require => { QUnit.test( 'DerivedProperty and/or', function( assert ) { - var propA = new Property( false ); - var propB = new Property( false ); - var propC = new Property( false ); - var propD = new Property( 0 ); // dependency with an invalid (non-boolean) type + const propA = new Property( false ); + const propB = new Property( false ); + const propC = new Property( false ); + const propD = new Property( 0 ); // dependency with an invalid (non-boolean) type // fail: 'and' with non-boolean Property window.assert && assert.throws( function() { return DerivedProperty.and( [ propA, propD ] ); }, @@ -76,8 +76,8 @@ define( require => { 'DerivedProperty.or requires booleans Property values' ); // correct usages of 'and' and 'or' - var and = DerivedProperty.and( [ propA, propB, propC ] ); - var or = DerivedProperty.or( [ propA, propB, propC ] ); + const and = DerivedProperty.and( [ propA, propB, propC ] ); + const or = DerivedProperty.or( [ propA, propB, propC ] ); assert.equal( and.value, false ); assert.equal( or.value, false ); diff --git a/js/DynamicPropertyTests.js b/js/DynamicPropertyTests.js index cb476338..7a363936 100644 --- a/js/DynamicPropertyTests.js +++ b/js/DynamicPropertyTests.js @@ -15,10 +15,10 @@ define( require => { QUnit.module( 'DynamicProperty' ); QUnit.test( 'Basics', function( assert ) { - var aProperty = new Property( 5 ); // eslint-disable-line no-undef - var bProperty = new Property( 2 ); // eslint-disable-line no-undef - var propertyProperty = new Property( aProperty ); // eslint-disable-line no-undef - var dynamicProperty = new DynamicProperty( propertyProperty ); // eslint-disable-line no-undef + const aProperty = new Property( 5 ); // eslint-disable-line no-undef + const bProperty = new Property( 2 ); // eslint-disable-line no-undef + const propertyProperty = new Property( aProperty ); // eslint-disable-line no-undef + const dynamicProperty = new DynamicProperty( propertyProperty ); // eslint-disable-line no-undef assert.equal( dynamicProperty.value, aProperty.value ); @@ -34,14 +34,14 @@ define( require => { } ); QUnit.test( 'Derive (string)', function( assert ) { - var a = { + const a = { property: new Property( 5 ) // eslint-disable-line no-undef }; - var b = { + const b = { property: new Property( 2 ) // eslint-disable-line no-undef }; - var mainProperty = new Property( a ); // eslint-disable-line no-undef - var dynamicProperty = new DynamicProperty( mainProperty, { // eslint-disable-line no-undef + const mainProperty = new Property( a ); // eslint-disable-line no-undef + const dynamicProperty = new DynamicProperty( mainProperty, { // eslint-disable-line no-undef derive: 'property' } ); @@ -59,14 +59,14 @@ define( require => { } ); QUnit.test( 'Derive (function)', function( assert ) { - var a = { + const a = { property: new Property( 5 ) // eslint-disable-line no-undef }; - var b = { + const b = { property: new Property( 2 ) // eslint-disable-line no-undef }; - var mainProperty = new Property( a ); // eslint-disable-line no-undef - var dynamicProperty = new DynamicProperty( mainProperty, { // eslint-disable-line no-undef + const mainProperty = new Property( a ); // eslint-disable-line no-undef + const dynamicProperty = new DynamicProperty( mainProperty, { // eslint-disable-line no-undef derive: function( ob ) { return ob.property; } @@ -86,10 +86,10 @@ define( require => { } ); QUnit.test( 'Bidirectional', function( assert ) { - var firstProperty = new Property( 5 ); // eslint-disable-line no-undef - var secondProperty = new Property( 10 ); // eslint-disable-line no-undef - var numberPropertyProperty = new Property( firstProperty ); // eslint-disable-line no-undef - var dynamicProperty = new DynamicProperty( numberPropertyProperty, { bidirectional: true } ); // eslint-disable-line no-undef + const firstProperty = new Property( 5 ); // eslint-disable-line no-undef + const secondProperty = new Property( 10 ); // eslint-disable-line no-undef + const numberPropertyProperty = new Property( firstProperty ); // eslint-disable-line no-undef + const dynamicProperty = new DynamicProperty( numberPropertyProperty, { bidirectional: true } ); // eslint-disable-line no-undef dynamicProperty.value = 2; // allowed now that it is bidrectional, otherwise prohibited assert.equal( firstProperty.value, 2 ); @@ -103,10 +103,10 @@ define( require => { } ); QUnit.test( 'Mapping (with bidirectional)', function( assert ) { - var firstProperty = new Property( 5 ); // eslint-disable-line no-undef - var secondProperty = new Property( 10 ); // eslint-disable-line no-undef - var numberPropertyProperty = new Property( firstProperty ); // eslint-disable-line no-undef - var dynamicProperty = new DynamicProperty( numberPropertyProperty, { // eslint-disable-line no-undef + const firstProperty = new Property( 5 ); // eslint-disable-line no-undef + const secondProperty = new Property( 10 ); // eslint-disable-line no-undef + const numberPropertyProperty = new Property( firstProperty ); // eslint-disable-line no-undef + const dynamicProperty = new DynamicProperty( numberPropertyProperty, { // eslint-disable-line no-undef bidirectional: true, map: function( number ) { return '' + number; @@ -131,9 +131,9 @@ define( require => { } ); QUnit.test( 'Attempted setters to nonbidrectional', function( assert ) { - var property = new Property( 5 ); - var propertyProperty = new Property( property ); - var dynamicProperty = new DynamicProperty( propertyProperty ); + const property = new Property( 5 ); + const propertyProperty = new Property( property ); + const dynamicProperty = new DynamicProperty( propertyProperty ); window.assert && assert.throws( function() { dynamicProperty.value = 10; @@ -147,17 +147,17 @@ define( require => { } ); QUnit.test( 'Bidirectional prevention of pingponging', function( assert ) { - var callbackCount = 0; + let callbackCount = 0; - var sourceProperty = new Property( 0 ); + const sourceProperty = new Property( 0 ); sourceProperty.link( function() { if ( callbackCount++ > 500 ) { throw new Error( 'Infinite loop detected' ); } } ); - var wrapperProperty = new Property( sourceProperty ); - var dynamicProperty = new DynamicProperty( wrapperProperty, { + const wrapperProperty = new Property( sourceProperty ); + const dynamicProperty = new DynamicProperty( wrapperProperty, { bidirectional: true, // NOT a true inverse map: n => n + 2, diff --git a/js/Events.js b/js/Events.js index 09cc9267..fef30007 100644 --- a/js/Events.js +++ b/js/Events.js @@ -113,7 +113,7 @@ define( require => { assert && assert( typeof eventName === 'string', 'eventName should be a string' ); assert && assert( typeof callback === 'function', 'callback should be a function' ); - var array = this._eventListeners[ eventName ]; + const array = this._eventListeners[ eventName ]; return !!array && array.indexOf( callback ) >= 0; }, @@ -128,7 +128,7 @@ define( require => { assert && assert( typeof eventName === 'string', 'eventName should be a string' ); assert && assert( typeof callback === 'function', 'callback should be a function' ); - var array = this._staticEventListeners[ eventName ]; + const array = this._staticEventListeners[ eventName ]; return !!array && array.indexOf( callback ) >= 0; }, @@ -137,7 +137,7 @@ define( require => { * @public */ removeAllEventListeners: function() { - var eventName; + let eventName; for ( eventName in this._eventListeners ) { cleanArray( this._eventListeners[ eventName ] ); } @@ -155,16 +155,16 @@ define( require => { trigger: function( eventName ) { assert && assert( typeof eventName === 'string', 'eventName should be a string' ); - var listeners = this._eventListeners[ eventName ]; - var staticListeners = this._staticEventListeners[ eventName ]; + let listeners = this._eventListeners[ eventName ]; + const staticListeners = this._staticEventListeners[ eventName ]; // listener quantities for normal and static - var count = listeners ? listeners.length : 0; - var staticCount = staticListeners ? staticListeners.length : 0; + const count = listeners ? listeners.length : 0; + const staticCount = staticListeners ? staticListeners.length : 0; // only compute our arguments suffix once, instead of in our inner loop - var suffix; - var hasNoArguments = arguments.length === 1; + let suffix; + const hasNoArguments = arguments.length === 1; if ( !hasNoArguments && ( count > 0 || staticCount > 0 ) ) { suffix = Array.prototype.slice.call( arguments, 1 ); } @@ -174,10 +174,10 @@ define( require => { listeners = listeners.slice(); } - var i; + let i; for ( i = 0; i < count; i++ ) { - var listener = listeners[ i ]; + const listener = listeners[ i ]; //Simple case of no arguments, call it separately for improved performance in case it is faster (untested) if ( hasNoArguments ) { @@ -191,7 +191,7 @@ define( require => { } for ( i = 0; i < staticCount; i++ ) { - var staticListener = staticListeners[ i ]; + const staticListener = staticListeners[ i ]; //Simple case of no arguments, call it separately for improved performance in case it is faster (untested) if ( hasNoArguments ) { @@ -215,19 +215,19 @@ define( require => { assert && assert( arguments.length === 1 ); assert && assert( typeof eventName === 'string', 'eventName should be a string' ); - var listeners = this._eventListeners[ eventName ]; - var staticListeners = this._staticEventListeners[ eventName ]; + let listeners = this._eventListeners[ eventName ]; + const staticListeners = this._staticEventListeners[ eventName ]; // listener quantities for normal and static - var count = listeners ? listeners.length : 0; - var staticCount = staticListeners ? staticListeners.length : 0; + const count = listeners ? listeners.length : 0; + const staticCount = staticListeners ? staticListeners.length : 0; // make a copy of non-static listeners, in case callback removes listener if ( count > 0 ) { listeners = listeners.slice(); } - var i; + let i; for ( i = 0; i < count; i++ ) { listeners[ i ](); @@ -253,19 +253,19 @@ define( require => { assert && assert( arguments.length === 2 ); assert && assert( typeof eventName === 'string', 'eventName should be a string' ); - var listeners = this._eventListeners[ eventName ]; - var staticListeners = this._staticEventListeners[ eventName ]; + let listeners = this._eventListeners[ eventName ]; + const staticListeners = this._staticEventListeners[ eventName ]; // listener quantities for normal and static - var count = listeners ? listeners.length : 0; - var staticCount = staticListeners ? staticListeners.length : 0; + const count = listeners ? listeners.length : 0; + const staticCount = staticListeners ? staticListeners.length : 0; // make a copy of non-static listeners, in case callback removes listener if ( count > 0 ) { listeners = listeners.slice(); } - var i; + let i; for ( i = 0; i < count; i++ ) { listeners[ i ]( param1 ); @@ -292,19 +292,19 @@ define( require => { assert && assert( arguments.length === 3 ); assert && assert( typeof eventName === 'string', 'eventName should be a string' ); - var listeners = this._eventListeners[ eventName ]; - var staticListeners = this._staticEventListeners[ eventName ]; + let listeners = this._eventListeners[ eventName ]; + const staticListeners = this._staticEventListeners[ eventName ]; // listener quantities for normal and static - var count = listeners ? listeners.length : 0; - var staticCount = staticListeners ? staticListeners.length : 0; + const count = listeners ? listeners.length : 0; + const staticCount = staticListeners ? staticListeners.length : 0; // make a copy of non-static listeners, in case callback removes listener if ( count > 0 ) { listeners = listeners.slice(); } - var i; + let i; for ( i = 0; i < count; i++ ) { listeners[ i ]( param1, param2 ); diff --git a/js/EventsTests.js b/js/EventsTests.js index 1554b629..25c7f02a 100644 --- a/js/EventsTests.js +++ b/js/EventsTests.js @@ -14,11 +14,11 @@ define( require => { QUnit.module( 'Events' ); QUnit.test( 'Basics', function( assert ) { - var events = new Events(); // eslint-disable-line no-undef + const events = new Events(); // eslint-disable-line no-undef events.trigger( 'doesNotExist', 1, 2, 3 ); // shouldn't error on non-existent event name - var aCount = 0; + let aCount = 0; function incrementA() { aCount++; } @@ -37,9 +37,9 @@ define( require => { assert.equal( events.hasListener( 'a', incrementA ), false, 'Should not have increment listener after off()' ); - var person = new Events( { name: 'larry', age: '100' } ); - var count = 0; - var listener = function( person ) { + const person = new Events( { name: 'larry', age: '100' } ); + let count = 0; + const listener = function( person ) { count = count + 1; }; person.on( 'reset-all', listener ); @@ -60,8 +60,8 @@ define( require => { assert.equal( count, 3, 'Triggering more events should not call back because we have removed the listener' ); - var planetName = '?'; - var planetRadius = '?'; + let planetName = '?'; + let planetRadius = '?'; person.on( 'planet-discovered', function( name, radius ) { planetName = name; planetRadius = radius; @@ -74,11 +74,11 @@ define( require => { } ); QUnit.test( 'Static Basics', function( assert ) { - var events = new Events(); // eslint-disable-line no-undef + const events = new Events(); // eslint-disable-line no-undef events.trigger( 'doesNotExist', 1, 2, 3 ); // shouldn't error on non-existent event name - var aCount = 0; + let aCount = 0; function incrementA() { aCount++; } diff --git a/js/Multilink.js b/js/Multilink.js index 552b2158..ed3775f9 100644 --- a/js/Multilink.js +++ b/js/Multilink.js @@ -27,14 +27,14 @@ define( require => { assert && assert( dependencies.length === _.uniq( dependencies ).length, 'duplicate dependencies' ); - var self = this; + const self = this; // @private Keep track of listeners so they can be detached this.dependencyListeners = []; // When a dependency value changes, update the list of dependencies and call back to the callback dependencies.forEach( function( dependency, i ) { - var listener = function( value ) { + const listener = function( value ) { // don't call listener if this Multilink has been disposed, see https://github.com/phetsims/axon/issues/192 if ( !self.isDisposed ) { @@ -63,8 +63,8 @@ define( require => { assert && assert( this.dependencies, 'A Multilink cannot be disposed twice.' ); // Unlink from dependent properties - for ( var i = 0; i < this.dependencies.length; i++ ) { - var dependency = this.dependencies[ i ]; + for ( let i = 0; i < this.dependencies.length; i++ ) { + const dependency = this.dependencies[ i ]; if ( !dependency.isDisposed ) { dependency.unlink( this.dependencyListeners[ i ] ); } diff --git a/js/NumberPropertyTests.js b/js/NumberPropertyTests.js index 5c3076e0..d590808d 100644 --- a/js/NumberPropertyTests.js +++ b/js/NumberPropertyTests.js @@ -18,7 +18,7 @@ define( require => { QUnit.test( 'Test NumberProperty', function( assert ) { - var p = null; + let p = null; // valueType window.assert && assert.throws( function() { diff --git a/js/ObservableArray.js b/js/ObservableArray.js index 7e35be4d..329c254a 100644 --- a/js/ObservableArray.js +++ b/js/ObservableArray.js @@ -22,7 +22,7 @@ define( require => { const Tandem = require( 'TANDEM/Tandem' ); // Factor out to reduce memory footprint, see https://github.com/phetsims/tandem/issues/71 - var DefaultObservableArrayIOType = ObservableArrayIO( ObjectIO ); + const DefaultObservableArrayIOType = ObservableArrayIO( ObjectIO ); /** * @param {Object} [options] @@ -97,7 +97,7 @@ define( require => { * @public */ removeItemAddedListener: function( listener ) { - var index = this._addedListeners.indexOf( listener ); + const index = this._addedListeners.indexOf( listener ); assert && assert( index !== -1 ); // listener is registered this._addedListeners.splice( index, 1 ); }, @@ -118,21 +118,21 @@ define( require => { * @public */ removeItemRemovedListener: function( listener ) { - var index = this._removedListeners.indexOf( listener ); + const index = this._removedListeners.indexOf( listener ); assert && assert( index !== -1, 'Listener is still registered after removal' ); // listener is registered this._removedListeners.splice( index, 1 ); }, // @private called when an item is added. _fireItemAdded: function( item ) { - var self = this; + const self = this; this.phetioStartEvent( 'itemAdded', function() { return self.phetioType.parameterType.toStateObject( item ); } ); //Signify that an item was added to the list - var copy = this._addedListeners.slice( 0 ); // operate on a copy, firing could result in the listeners changing - for ( var i = 0; i < copy.length; i++ ) { + const copy = this._addedListeners.slice( 0 ); // operate on a copy, firing could result in the listeners changing + for ( let i = 0; i < copy.length; i++ ) { copy[ i ]( item, this ); } @@ -141,14 +141,14 @@ define( require => { // @private called when an item is removed. _fireItemRemoved: function( item ) { - var self = this; + const self = this; this.phetioStartEvent( 'itemRemoved', function() { return self.phetioType.parameterType.toStateObject( item ); } ); //Signify that an item was removed from the list - var copy = this._removedListeners.slice( 0 ); // operate on a copy, firing could result in the listeners changing - for ( var i = 0; i < copy.length; i++ ) { + const copy = this._removedListeners.slice( 0 ); // operate on a copy, firing could result in the listeners changing + for ( let i = 0; i < copy.length; i++ ) { copy[ i ]( item, this ); } @@ -172,7 +172,7 @@ define( require => { * @public */ addAll: function( items ) { - for ( var i = 0; i < items.length; i++ ) { + for ( let i = 0; i < items.length; i++ ) { this.add( items[ i ] ); } }, @@ -185,7 +185,7 @@ define( require => { * @public */ remove: function( item ) { - var index = this._array.indexOf( item ); + const index = this._array.indexOf( item ); if ( index !== -1 ) { this._array.splice( index, 1 ); this.lengthProperty.set( this._array.length ); @@ -201,7 +201,7 @@ define( require => { */ removeAll: function( array ) { assert && assert( _.isArray( array ), 'array should be an array' ); - for ( var i = 0; i < array.length; i++ ) { + for ( let i = 0; i < array.length; i++ ) { this.remove( array[ i ] ); } }, @@ -229,7 +229,7 @@ define( require => { pop: function() { // TODO: should we really pop if the length was 0? Or maybe this is OK? - var item = this._array.pop(); + const item = this._array.pop(); if ( item !== undefined ) { this.lengthProperty.set( this._array.length ); this._fireItemRemoved( item ); @@ -243,7 +243,7 @@ define( require => { * @public */ shift: function() { - var item = this._array.shift(); + const item = this._array.shift(); if ( item !== undefined ) { this.lengthProperty.set( this._array.length ); this._fireItemRemoved( item ); @@ -331,8 +331,8 @@ define( require => { * @public */ count: function( predicate ) { - var count = 0; - for ( var i = 0; i < this._array.length; i++ ) { + let count = 0; + for ( let i = 0; i < this._array.length; i++ ) { if ( predicate( this._array[ i ] ) ) { count++; } @@ -367,7 +367,7 @@ define( require => { * @public */ reduce: function( value, combiner ) { - for ( var i = 0; i < this._array.length; i++ ) { + for ( let i = 0; i < this._array.length; i++ ) { value = combiner( value, this._array[ i ] ); } return value; @@ -393,13 +393,13 @@ define( require => { * @public */ splice: function( start, deleteCount, item1, item2, etc ) { - var deleted = this._array.splice.apply( this._array, arguments ); - var args = Array.prototype.slice.call( arguments ); - for ( var i = 0; i < deleted.length; i++ ) { + const deleted = this._array.splice.apply( this._array, arguments ); + const args = Array.prototype.slice.call( arguments ); + for ( let i = 0; i < deleted.length; i++ ) { this._fireItemRemoved( deleted[ i ] ); } - for ( var k = 2; k < args.length; k++ ) { + for ( let k = 2; k < args.length; k++ ) { this._fireItemAdded( args[ k ] ); } return deleted; @@ -414,7 +414,7 @@ define( require => { assert && assert( random, 'random must be supplied' ); // preserve the same _array reference in case any clients got a reference to it with getArray() - var shuffled = random.shuffle( this._array ); + const shuffled = random.shuffle( this._array ); this._array.length = 0; Array.prototype.push.apply( this._array, shuffled ); } diff --git a/js/ObservableArrayTests.js b/js/ObservableArrayTests.js index af0f5aeb..75e5eada 100644 --- a/js/ObservableArrayTests.js +++ b/js/ObservableArrayTests.js @@ -14,11 +14,11 @@ define( require => { QUnit.module( 'Observable Array' ); QUnit.test( 'Test observable array', function( assert ) { - var array = new ObservableArray(); + const array = new ObservableArray(); array.push( 'a' ); array.push( 'b' ); array.push( 'c' ); - var dChecker = function( item ) { + const dChecker = function( item ) { assert.equal( item, 'd' ); }; array.addItemAddedListener( dChecker ); @@ -29,16 +29,16 @@ define( require => { assert.equal( array.length, 0 ); // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice - var myFish = [ 'angel', 'clown', 'mandarin', 'surgeon' ]; - var myFish2 = new ObservableArray(); + const myFish = [ 'angel', 'clown', 'mandarin', 'surgeon' ]; + const myFish2 = new ObservableArray(); myFish2.push( 'angel' ); myFish2.push( 'clown' ); myFish2.push( 'mandarin' ); myFish2.push( 'surgeon' ); - var addedCount = 0; - var removedCount = 0; - var addedOrder = [ 'drum', 'trumpet', 'parrot', 'anemone', 'blue' ]; - var removedOrder = [ 'mandarin', 'drum', 'angel', 'clown', 'blue', 'trumpet' ]; + let addedCount = 0; + let removedCount = 0; + const addedOrder = [ 'drum', 'trumpet', 'parrot', 'anemone', 'blue' ]; + const removedOrder = [ 'mandarin', 'drum', 'angel', 'clown', 'blue', 'trumpet' ]; myFish2.addItemAddedListener( function( item ) { assert.equal( item, addedOrder[ addedCount ], 'wrong item added' ); addedCount++; @@ -51,8 +51,8 @@ define( require => { assert.deepEqual( myFish, myFish2.getArray(), 'arrays should match to start' ); // removes 0 elements from index 2, and inserts 'drum' - var removed = myFish.splice( 2, 0, 'drum' ); - var removed2 = myFish2.splice( 2, 0, 'drum' ); + let removed = myFish.splice( 2, 0, 'drum' ); + let removed2 = myFish2.splice( 2, 0, 'drum' ); assert.deepEqual( myFish, myFish2.getArray(), 'arrays should match' ); assert.deepEqual( removed, removed2, 'removed should be equal' ); // myFish is ['angel', 'clown', 'drum', 'mandarin', 'surgeon'] diff --git a/js/PropertyIO.js b/js/PropertyIO.js index 146655ee..ebbfa894 100644 --- a/js/PropertyIO.js +++ b/js/PropertyIO.js @@ -52,7 +52,7 @@ define( require => { static toStateObject( property ) { validate( property, this.validator ); assert && assert( parameterType.toStateObject, 'toStateObject doesnt exist for ' + parameterType.typeName ); - var stateObject = { + const stateObject = { value: parameterType.toStateObject( property.value ) }; diff --git a/js/PropertyTests.js b/js/PropertyTests.js index b8d76bb5..ba12970a 100644 --- a/js/PropertyTests.js +++ b/js/PropertyTests.js @@ -17,10 +17,10 @@ define( require => { QUnit.module( 'Property' ); QUnit.test( 'Test unlink', function( assert ) { - var p = new Property( 1 ); - var a = function( a ) {}; - var b = function( b ) {}; - var c = function( c ) {}; + const p = new Property( 1 ); + const a = function( a ) {}; + const b = function( b ) {}; + const c = function( c ) {}; p.link( a ); p.link( b ); p.link( c ); @@ -32,9 +32,9 @@ define( require => { } ); QUnit.test( 'Test Property.multilink', function( assert ) { - var a = new Property( 1 ); - var b = new Property( 2 ); - var callbacks = 0; + const a = new Property( 1 ); + const b = new Property( 2 ); + let callbacks = 0; Property.multilink( [ a, b ], function( a, b ) { callbacks++; assert.equal( a, 1, 'first value should pass through' ); @@ -44,9 +44,9 @@ define( require => { } ); QUnit.test( 'Test Property.lazyMultilink', function( assert ) { - var a = new Property( 1 ); - var b = new Property( 2 ); - var callbacks = 0; + const a = new Property( 1 ); + const b = new Property( 2 ); + let callbacks = 0; Property.lazyMultilink( [ a, b ], function( a, b ) { callbacks++; assert.equal( a, 1 ); @@ -56,8 +56,8 @@ define( require => { } ); QUnit.test( 'Test defer', function( assert ) { - var property = new Property( 0 ); - var callbacks = 0; + const property = new Property( 0 ); + let callbacks = 0; property.lazyLink( function( newValue, oldValue ) { callbacks++; assert.equal( newValue, 2, 'newValue should be the final value after the transaction' ); @@ -67,7 +67,7 @@ define( require => { property.value = 1; property.value = 2; assert.equal( property.value, 0, 'should have original value' ); - var update = property.setDeferred( false ); + const update = property.setDeferred( false ); assert.equal( callbacks, 0, 'should not call back while deferred' ); assert.equal( property.value, 2, 'should have new value' ); update(); @@ -80,8 +80,8 @@ define( require => { } ); QUnit.test( 'Property link parameters', function( assert ) { - var p = new Property( 1 ); - var calls = []; + const p = new Property( 1 ); + const calls = []; p.link( function( newValue, oldValue, property ) { calls.push( { newValue: newValue, @@ -106,9 +106,9 @@ define( require => { * Make sure linking attributes and unlinking attributes works on Property */ QUnit.test( 'Property.linkAttribute', function( assert ) { - var property = new Property( 7 ); - var state = { age: 99 }; - var listener = property.linkAttribute( state, 'age' ); + const property = new Property( 7 ); + const state = { age: 99 }; + const listener = property.linkAttribute( state, 'age' ); assert.equal( state.age, 7, 'link should synchronize values' ); property.value = 8; assert.equal( state.age, 8, 'link should update values' ); @@ -122,8 +122,8 @@ define( require => { // Type that is specific to valueType tests function TestType() {} - var property = null; - var options = {}; + let property = null; + let options = {}; // valueType is a primitive type (typeof validation) options = { @@ -229,8 +229,8 @@ define( require => { // Tests that can only run in phet-io mode if ( window.phet.phetio ) { QUnit.test( 'Test PropertyIO toStateObject/fromStateObject', function( assert ) { - var done = assert.async(); - var tandem = Tandem.rootTandem.createTandem( 'testTandemProperty' ); + const done = assert.async(); + const tandem = Tandem.rootTandem.createTandem( 'testTandemProperty' ); const phetioType = NumberPropertyIO; const propertyValue = 123; const validValues = [ 0, 1, 2, 3, propertyValue ]; @@ -242,7 +242,7 @@ define( require => { setTimeout( () => { // Run in the next frame after the object finished getting constructed - var stateObject = phetioType.toStateObject( instance ); + const stateObject = phetioType.toStateObject( instance ); assert.equal( stateObject.value, propertyValue, 'toStateObject should match' ); assert.deepEqual( stateObject.validValues, validValues, 'toStateObject should match' ); done(); diff --git a/js/StringPropertyTests.js b/js/StringPropertyTests.js index 7ae30360..ee45e596 100644 --- a/js/StringPropertyTests.js +++ b/js/StringPropertyTests.js @@ -16,7 +16,7 @@ define( require => { QUnit.module( 'StringProperty' ); QUnit.test( 'Test StringProperty', function( assert ) { - var p = null; + let p = null; // valueType window.assert && assert.throws( function() {