Skip to content

Commit 8d254a4

Browse files
committed
Fix issue where Firefox Promise then callback can not correctly keep track of its key
1 parent 2fcc931 commit 8d254a4

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

examples/js/loaders/GLTFLoader.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ GLTFShader.prototype.update = function( scene, camera ) {
247247

248248
}
249249

250-
}.bind(this));
250+
}.bind( this ));
251251

252252
};
253253

@@ -569,33 +569,38 @@ var _each = function( object, callback, thisObj ) {
569569
results = [];
570570

571571
var length = object.length;
572-
for ( let idx = 0; idx < length; idx ++ ) {
573-
let value = callback.call( thisObj || this, object[ idx ], idx );
574-
fns.push( value );
575-
if ( value && value instanceof Promise ) {
576-
value.then( function( value ) {
572+
for ( var idx = 0; idx < length; idx ++ ) {
573+
var value = callback.call( thisObj || this, object[ idx ], idx );
574+
if ( value ) {
575+
fns.push( value );
576+
if ( value instanceof Promise ) {
577+
value.then( function( key, value ) {
578+
results[ idx ] = value;
579+
}.bind( this, key ));
580+
} else {
577581
results[ idx ] = value;
578-
});
579-
} else {
580-
results[ idx ] = value;
582+
}
581583
}
582584

583585
}
584586

585587
} else {
586588

589+
587590
results = {};
588591

589-
for ( let key in object ) {
592+
for ( var key in object ) {
590593
if ( object.hasOwnProperty( key ) ) {
591-
let value = callback.call( thisObj || this, object[ key ], key );
592-
fns.push( value );
593-
if ( value && value instanceof Promise ) {
594-
value.then( function( value ) {
594+
var value = callback.call( thisObj || this, object[ key ], key );
595+
if ( value ) {
596+
fns.push( value );
597+
if ( value instanceof Promise ) {
598+
value.then( function( key, value ) {
599+
results[ key ] = value;
600+
}.bind( this, key ));
601+
} else {
595602
results[ key ] = value;
596-
});
597-
} else {
598-
results[ key ] = value;
603+
}
599604
}
600605
}
601606
}

0 commit comments

Comments
 (0)