瀏覽代碼

Loaders: Move to let/const.

Mugen87 5 年之前
父節點
當前提交
ed202faac3

+ 5 - 5
src/loaders/AnimationLoader.js

@@ -18,9 +18,9 @@ AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var loader = new FileLoader( scope.manager );
+		const loader = new FileLoader( scope.manager );
 		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
@@ -50,11 +50,11 @@ AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parse: function ( json ) {
 
-		var animations = [];
+		const animations = [];
 
-		for ( var i = 0; i < json.length; i ++ ) {
+		for ( let i = 0; i < json.length; i ++ ) {
 
-			var clip = AnimationClip.parse( json[ i ] );
+			const clip = AnimationClip.parse( json[ i ] );
 
 			animations.push( clip );
 

+ 4 - 4
src/loaders/AudioLoader.js

@@ -18,9 +18,9 @@ AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var loader = new FileLoader( scope.manager );
+		const loader = new FileLoader( scope.manager );
 		loader.setResponseType( 'arraybuffer' );
 		loader.setPath( scope.path );
 		loader.load( url, function ( buffer ) {
@@ -29,9 +29,9 @@ AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				// Create a copy of the buffer. The `decodeAudioData` method
 				// detaches the buffer when complete, preventing reuse.
-				var bufferCopy = buffer.slice( 0 );
+				const bufferCopy = buffer.slice( 0 );
 
-				var context = AudioContext.getContext();
+				const context = AudioContext.getContext();
 				context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
 
 					onLoad( audioBuffer );

+ 26 - 26
src/loaders/BufferGeometryLoader.js

@@ -23,9 +23,9 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var loader = new FileLoader( scope.manager );
+		const loader = new FileLoader( scope.manager );
 		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
@@ -55,46 +55,46 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 	parse: function ( json ) {
 
-		var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
+		const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
 
-		var index = json.data.index;
+		const index = json.data.index;
 
 		if ( index !== undefined ) {
 
-			var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
+			const typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
 			geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
 
 		}
 
-		var attributes = json.data.attributes;
+		const attributes = json.data.attributes;
 
-		for ( var key in attributes ) {
+		for ( const key in attributes ) {
 
-			var attribute = attributes[ key ];
-			var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
-			var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
-			var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
+			const attribute = attributes[ key ];
+			const typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
+			const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
+			const bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
 			if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
 			geometry.setAttribute( key, bufferAttribute );
 
 		}
 
-		var morphAttributes = json.data.morphAttributes;
+		const morphAttributes = json.data.morphAttributes;
 
 		if ( morphAttributes ) {
 
-			for ( var key in morphAttributes ) {
+			for ( const key in morphAttributes ) {
 
-				var attributeArray = morphAttributes[ key ];
+				const attributeArray = morphAttributes[ key ];
 
-				var array = [];
+				const array = [];
 
-				for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
+				for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
 
-					var attribute = attributeArray[ i ];
-					var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
+					const attribute = attributeArray[ i ];
+					const typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
 
-					var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
+					const bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
 					if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
 					array.push( bufferAttribute );
 
@@ -106,7 +106,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 		}
 
-		var morphTargetsRelative = json.data.morphTargetsRelative;
+		const morphTargetsRelative = json.data.morphTargetsRelative;
 
 		if ( morphTargetsRelative ) {
 
@@ -114,13 +114,13 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 		}
 
-		var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
+		const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
 
 		if ( groups !== undefined ) {
 
-			for ( var i = 0, n = groups.length; i !== n; ++ i ) {
+			for ( let i = 0, n = groups.length; i !== n; ++ i ) {
 
-				var group = groups[ i ];
+				const group = groups[ i ];
 
 				geometry.addGroup( group.start, group.count, group.materialIndex );
 
@@ -128,11 +128,11 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 		}
 
-		var boundingSphere = json.data.boundingSphere;
+		const boundingSphere = json.data.boundingSphere;
 
 		if ( boundingSphere !== undefined ) {
 
-			var center = new Vector3();
+			const center = new Vector3();
 
 			if ( boundingSphere.center !== undefined ) {
 
@@ -153,7 +153,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 } );
 
-var TYPED_ARRAYS = {
+const TYPED_ARRAYS = {
 	Int8Array: Int8Array,
 	Uint8Array: Uint8Array,
 	// Workaround for IE11 pre KB2929437. See #11440

+ 1 - 1
src/loaders/Cache.js

@@ -2,7 +2,7 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
-var Cache = {
+const Cache = {
 
 	enabled: false,
 

+ 12 - 12
src/loaders/CompressedTextureLoader.js

@@ -23,22 +23,24 @@ CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototy
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var images = [];
+		const images = [];
 
-		var texture = new CompressedTexture();
+		const texture = new CompressedTexture();
 		texture.image = images;
 
-		var loader = new FileLoader( this.manager );
+		const loader = new FileLoader( this.manager );
 		loader.setPath( this.path );
 		loader.setResponseType( 'arraybuffer' );
 
+		let loaded = 0;
+
 		function loadTexture( i ) {
 
 			loader.load( url[ i ], function ( buffer ) {
 
-				var texDatas = scope.parse( buffer, true );
+				const texDatas = scope.parse( buffer, true );
 
 				images[ i ] = {
 					width: texDatas.width,
@@ -67,9 +69,7 @@ CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototy
 
 		if ( Array.isArray( url ) ) {
 
-			var loaded = 0;
-
-			for ( var i = 0, il = url.length; i < il; ++ i ) {
+			for ( let i = 0, il = url.length; i < il; ++ i ) {
 
 				loadTexture( i );
 
@@ -81,17 +81,17 @@ CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototy
 
 			loader.load( url, function ( buffer ) {
 
-				var texDatas = scope.parse( buffer, true );
+				const texDatas = scope.parse( buffer, true );
 
 				if ( texDatas.isCubemap ) {
 
-					var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
+					const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
 
-					for ( var f = 0; f < faces; f ++ ) {
+					for ( let f = 0; f < faces; f ++ ) {
 
 						images[ f ] = { mipmaps: [] };
 
-						for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
+						for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
 
 							images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
 							images[ f ].format = texDatas.format;

+ 4 - 4
src/loaders/CubeTextureLoader.js

@@ -19,13 +19,13 @@ CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 	load: function ( urls, onLoad, onProgress, onError ) {
 
-		var texture = new CubeTexture();
+		const texture = new CubeTexture();
 
-		var loader = new ImageLoader( this.manager );
+		const loader = new ImageLoader( this.manager );
 		loader.setCrossOrigin( this.crossOrigin );
 		loader.setPath( this.path );
 
-		var loaded = 0;
+		let loaded = 0;
 
 		function loadTexture( i ) {
 
@@ -47,7 +47,7 @@ CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 		}
 
-		for ( var i = 0; i < urls.length; ++ i ) {
+		for ( let i = 0; i < urls.length; ++ i ) {
 
 			loadTexture( i );
 

+ 4 - 4
src/loaders/DataTextureLoader.js

@@ -23,16 +23,16 @@ DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var texture = new DataTexture();
+		const texture = new DataTexture();
 
-		var loader = new FileLoader( this.manager );
+		const loader = new FileLoader( this.manager );
 		loader.setResponseType( 'arraybuffer' );
 		loader.setPath( this.path );
 		loader.load( url, function ( buffer ) {
 
-			var texData = scope.parse( buffer );
+			const texData = scope.parse( buffer );
 
 			if ( ! texData ) return;
 

+ 31 - 30
src/loaders/FileLoader.js

@@ -5,7 +5,7 @@
 import { Cache } from './Cache.js';
 import { Loader } from './Loader.js';
 
-var loading = {};
+const loading = {};
 
 function FileLoader( manager ) {
 
@@ -25,9 +25,9 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		url = this.manager.resolveURL( url );
 
-		var scope = this;
+		const scope = this;
 
-		var cached = Cache.get( url );
+		const cached = Cache.get( url );
 
 		if ( cached !== undefined ) {
 
@@ -62,33 +62,34 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 		}
 
 		// Check for data: URI
-		var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
-		var dataUriRegexResult = url.match( dataUriRegex );
+		const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
+		const dataUriRegexResult = url.match( dataUriRegex );
+		let request;
 
 		// Safari can not handle Data URIs through XMLHttpRequest so process manually
 		if ( dataUriRegexResult ) {
 
-			var mimeType = dataUriRegexResult[ 1 ];
-			var isBase64 = !! dataUriRegexResult[ 2 ];
-			var data = dataUriRegexResult[ 3 ];
+			const mimeType = dataUriRegexResult[ 1 ];
+			const isBase64 = !! dataUriRegexResult[ 2 ];
 
+			let data = dataUriRegexResult[ 3 ];
 			data = decodeURIComponent( data );
 
 			if ( isBase64 ) data = atob( data );
 
 			try {
 
-				var response;
-				var responseType = ( this.responseType || '' ).toLowerCase();
+				let response;
+				const responseType = ( this.responseType || '' ).toLowerCase();
 
 				switch ( responseType ) {
 
 					case 'arraybuffer':
 					case 'blob':
 
-						var view = new Uint8Array( data.length );
+						const view = new Uint8Array( data.length );
 
-						for ( var i = 0; i < data.length; i ++ ) {
+						for ( let i = 0; i < data.length; i ++ ) {
 
 							view[ i ] = data.charCodeAt( i );
 
@@ -108,7 +109,7 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 					case 'document':
 
-						var parser = new DOMParser();
+						const parser = new DOMParser();
 						response = parser.parseFromString( data, mimeType );
 
 						break;
@@ -164,15 +165,15 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			} );
 
-			var request = new XMLHttpRequest();
+			request = new XMLHttpRequest();
 
 			request.open( 'GET', url, true );
 
 			request.addEventListener( 'load', function ( event ) {
 
-				var response = this.response;
+				const response = this.response;
 
-				var callbacks = loading[ url ];
+				const callbacks = loading[ url ];
 
 				delete loading[ url ];
 
@@ -187,9 +188,9 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 					// error response bodies as proper responses to requests.
 					Cache.add( url, response );
 
-					for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
+					for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
 
-						var callback = callbacks[ i ];
+						const callback = callbacks[ i ];
 						if ( callback.onLoad ) callback.onLoad( response );
 
 					}
@@ -198,9 +199,9 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				} else {
 
-					for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
+					for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
 
-						var callback = callbacks[ i ];
+						const callback = callbacks[ i ];
 						if ( callback.onError ) callback.onError( event );
 
 					}
@@ -214,11 +215,11 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			request.addEventListener( 'progress', function ( event ) {
 
-				var callbacks = loading[ url ];
+				const callbacks = loading[ url ];
 
-				for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
+				for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
 
-					var callback = callbacks[ i ];
+					const callback = callbacks[ i ];
 					if ( callback.onProgress ) callback.onProgress( event );
 
 				}
@@ -227,13 +228,13 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			request.addEventListener( 'error', function ( event ) {
 
-				var callbacks = loading[ url ];
+				const callbacks = loading[ url ];
 
 				delete loading[ url ];
 
-				for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
+				for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
 
-					var callback = callbacks[ i ];
+					const callback = callbacks[ i ];
 					if ( callback.onError ) callback.onError( event );
 
 				}
@@ -245,13 +246,13 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			request.addEventListener( 'abort', function ( event ) {
 
-				var callbacks = loading[ url ];
+				const callbacks = loading[ url ];
 
 				delete loading[ url ];
 
-				for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
+				for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
 
-					var callback = callbacks[ i ];
+					const callback = callbacks[ i ];
 					if ( callback.onError ) callback.onError( event );
 
 				}
@@ -266,7 +267,7 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
 
-			for ( var header in this.requestHeader ) {
+			for ( const header in this.requestHeader ) {
 
 				request.setRequestHeader( header, this.requestHeader[ header ] );
 

+ 4 - 4
src/loaders/FontLoader.js

@@ -18,13 +18,13 @@ FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var loader = new FileLoader( this.manager );
+		const loader = new FileLoader( this.manager );
 		loader.setPath( this.path );
 		loader.load( url, function ( text ) {
 
-			var json;
+			let json;
 
 			try {
 
@@ -37,7 +37,7 @@ FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			}
 
-			var font = scope.parse( json );
+			const font = scope.parse( json );
 
 			if ( onLoad ) onLoad( font );
 

+ 2 - 2
src/loaders/ImageBitmapLoader.js

@@ -46,9 +46,9 @@ ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 		url = this.manager.resolveURL( url );
 
-		var scope = this;
+		const scope = this;
 
-		var cached = Cache.get( url );
+		const cached = Cache.get( url );
 
 		if ( cached !== undefined ) {
 

+ 3 - 3
src/loaders/ImageLoader.js

@@ -21,9 +21,9 @@ ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		url = this.manager.resolveURL( url );
 
-		var scope = this;
+		const scope = this;
 
-		var cached = Cache.get( url );
+		const cached = Cache.get( url );
 
 		if ( cached !== undefined ) {
 
@@ -41,7 +41,7 @@ ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		}
 
-		var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
+		const image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
 
 		function onImageLoad() {
 

+ 1 - 1
src/loaders/Loader.js

@@ -21,7 +21,7 @@ Object.assign( Loader.prototype, {
 
 	loadAsync: function ( url, onProgress ) {
 
-		var scope = this;
+		const scope = this;
 
 		return new Promise( function ( resolve, reject ) {
 

+ 4 - 4
src/loaders/LoaderUtils.js

@@ -2,7 +2,7 @@
  * @author Don McCurdy / https://www.donmccurdy.com
  */
 
-var LoaderUtils = {
+const LoaderUtils = {
 
 	decodeText: function ( array ) {
 
@@ -15,9 +15,9 @@ var LoaderUtils = {
 		// Avoid the String.fromCharCode.apply(null, array) shortcut, which
 		// throws a "maximum call stack size exceeded" error for large arrays.
 
-		var s = '';
+		let s = '';
 
-		for ( var i = 0, il = array.length; i < il; i ++ ) {
+		for ( let i = 0, il = array.length; i < il; i ++ ) {
 
 			// Implicitly assumes little-endian.
 			s += String.fromCharCode( array[ i ] );
@@ -40,7 +40,7 @@ var LoaderUtils = {
 
 	extractUrlBase: function ( url ) {
 
-		var index = url.lastIndexOf( '/' );
+		const index = url.lastIndexOf( '/' );
 
 		if ( index === - 1 ) return './';
 

+ 11 - 11
src/loaders/LoadingManager.js

@@ -4,13 +4,13 @@
 
 function LoadingManager( onLoad, onProgress, onError ) {
 
-	var scope = this;
+	const scope = this;
 
-	var isLoading = false;
-	var itemsLoaded = 0;
-	var itemsTotal = 0;
-	var urlModifier = undefined;
-	var handlers = [];
+	let isLoading = false;
+	let itemsLoaded = 0;
+	let itemsTotal = 0;
+	let urlModifier = undefined;
+	const handlers = [];
 
 	// Refer to #5689 for the reason why we don't set .onStart
 	// in the constructor
@@ -102,7 +102,7 @@ function LoadingManager( onLoad, onProgress, onError ) {
 
 	this.removeHandler = function ( regex ) {
 
-		var index = handlers.indexOf( regex );
+		const index = handlers.indexOf( regex );
 
 		if ( index !== - 1 ) {
 
@@ -116,10 +116,10 @@ function LoadingManager( onLoad, onProgress, onError ) {
 
 	this.getHandler = function ( file ) {
 
-		for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
+		for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
 
-			var regex = handlers[ i ];
-			var loader = handlers[ i + 1 ];
+			const regex = handlers[ i ];
+			const loader = handlers[ i + 1 ];
 
 			if ( regex.global ) regex.lastIndex = 0; // see #17920
 
@@ -137,7 +137,7 @@ function LoadingManager( onLoad, onProgress, onError ) {
 
 }
 
-var DefaultLoadingManager = new LoadingManager();
+const DefaultLoadingManager = new LoadingManager();
 
 
 export { DefaultLoadingManager, LoadingManager };

+ 8 - 8
src/loaders/MaterialLoader.js

@@ -26,9 +26,9 @@ MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var loader = new FileLoader( scope.manager );
+		const loader = new FileLoader( scope.manager );
 		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
@@ -58,7 +58,7 @@ MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parse: function ( json ) {
 
-		var textures = this.textures;
+		const textures = this.textures;
 
 		function getTexture( name ) {
 
@@ -72,7 +72,7 @@ MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		}
 
-		var material = new Materials[ json.type ]();
+		const material = new Materials[ json.type ]();
 
 		if ( json.uuid !== undefined ) material.uuid = json.uuid;
 		if ( json.name !== undefined ) material.name = json.name;
@@ -153,9 +153,9 @@ MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		if ( json.uniforms !== undefined ) {
 
-			for ( var name in json.uniforms ) {
+			for ( const name in json.uniforms ) {
 
-				var uniform = json.uniforms[ name ];
+				const uniform = json.uniforms[ name ];
 
 				material.uniforms[ name ] = {};
 
@@ -203,7 +203,7 @@ MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		if ( json.extensions !== undefined ) {
 
-			for ( var key in json.extensions ) {
+			for ( const key in json.extensions ) {
 
 				material.extensions[ key ] = json.extensions[ key ];
 
@@ -234,7 +234,7 @@ MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 		if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
 		if ( json.normalScale !== undefined ) {
 
-			var normalScale = json.normalScale;
+			let normalScale = json.normalScale;
 
 			if ( Array.isArray( normalScale ) === false ) {
 

+ 77 - 72
src/loaders/ObjectLoader.js

@@ -73,16 +73,16 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var scope = this;
+		const scope = this;
 
-		var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
+		const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
 		this.resourcePath = this.resourcePath || path;
 
-		var loader = new FileLoader( scope.manager );
+		const loader = new FileLoader( scope.manager );
 		loader.setPath( this.path );
 		loader.load( url, function ( text ) {
 
-			var json = null;
+			let json = null;
 
 			try {
 
@@ -98,7 +98,7 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			}
 
-			var metadata = json.metadata;
+			const metadata = json.metadata;
 
 			if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
 
@@ -115,19 +115,19 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parse: function ( json, onLoad ) {
 
-		var shapes = this.parseShape( json.shapes );
-		var geometries = this.parseGeometries( json.geometries, shapes );
+		const shapes = this.parseShape( json.shapes );
+		const geometries = this.parseGeometries( json.geometries, shapes );
 
-		var images = this.parseImages( json.images, function () {
+		const images = this.parseImages( json.images, function () {
 
 			if ( onLoad !== undefined ) onLoad( object );
 
 		} );
 
-		var textures = this.parseTextures( json.textures, images );
-		var materials = this.parseMaterials( json.materials, textures );
+		const textures = this.parseTextures( json.textures, images );
+		const materials = this.parseMaterials( json.materials, textures );
 
-		var object = this.parseObject( json.object, geometries, materials );
+		const object = this.parseObject( json.object, geometries, materials );
 
 		if ( json.animations ) {
 
@@ -147,13 +147,13 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parseShape: function ( json ) {
 
-		var shapes = {};
+		const shapes = {};
 
 		if ( json !== undefined ) {
 
-			for ( var i = 0, l = json.length; i < l; i ++ ) {
+			for ( let i = 0, l = json.length; i < l; i ++ ) {
 
-				var shape = new Shape().fromJSON( json[ i ] );
+				const shape = new Shape().fromJSON( json[ i ] );
 
 				shapes[ shape.uuid ] = shape;
 
@@ -167,16 +167,17 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parseGeometries: function ( json, shapes ) {
 
-		var geometries = {};
+		const geometries = {};
+		let geometryShapes;
 
 		if ( json !== undefined ) {
 
-			var bufferGeometryLoader = new BufferGeometryLoader();
+			const bufferGeometryLoader = new BufferGeometryLoader();
 
-			for ( var i = 0, l = json.length; i < l; i ++ ) {
+			for ( let i = 0, l = json.length; i < l; i ++ ) {
 
-				var geometry;
-				var data = json[ i ];
+				let geometry;
+				const data = json[ i ];
 
 				switch ( data.type ) {
 
@@ -364,11 +365,11 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 					case 'ShapeGeometry':
 					case 'ShapeBufferGeometry':
 
-						var geometryShapes = [];
+						geometryShapes = [];
 
-						for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
+						for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
 
-							var shape = shapes[ data.shapes[ j ] ];
+							const shape = shapes[ data.shapes[ j ] ];
 
 							geometryShapes.push( shape );
 
@@ -385,17 +386,17 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 					case 'ExtrudeGeometry':
 					case 'ExtrudeBufferGeometry':
 
-						var geometryShapes = [];
+						geometryShapes = [];
 
-						for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
+						for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
 
-							var shape = shapes[ data.shapes[ j ] ];
+							const shape = shapes[ data.shapes[ j ] ];
 
 							geometryShapes.push( shape );
 
 						}
 
-						var extrudePath = data.options.extrudePath;
+						const extrudePath = data.options.extrudePath;
 
 						if ( extrudePath !== undefined ) {
 
@@ -448,27 +449,27 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parseMaterials: function ( json, textures ) {
 
-		var cache = {}; // MultiMaterial
-		var materials = {};
+		const cache = {}; // MultiMaterial
+		const materials = {};
 
 		if ( json !== undefined ) {
 
-			var loader = new MaterialLoader();
+			const loader = new MaterialLoader();
 			loader.setTextures( textures );
 
-			for ( var i = 0, l = json.length; i < l; i ++ ) {
+			for ( let i = 0, l = json.length; i < l; i ++ ) {
 
-				var data = json[ i ];
+				const data = json[ i ];
 
 				if ( data.type === 'MultiMaterial' ) {
 
 					// Deprecated
 
-					var array = [];
+					const array = [];
 
-					for ( var j = 0; j < data.materials.length; j ++ ) {
+					for ( let j = 0; j < data.materials.length; j ++ ) {
 
-						var material = data.materials[ j ];
+						const material = data.materials[ j ];
 
 						if ( cache[ material.uuid ] === undefined ) {
 
@@ -504,13 +505,13 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parseAnimations: function ( json ) {
 
-		var animations = [];
+		const animations = [];
 
-		for ( var i = 0; i < json.length; i ++ ) {
+		for ( let i = 0; i < json.length; i ++ ) {
 
-			var data = json[ i ];
+			const data = json[ i ];
 
-			var clip = AnimationClip.parse( data );
+			const clip = AnimationClip.parse( data );
 
 			if ( data.uuid !== undefined ) clip.uuid = data.uuid;
 
@@ -524,8 +525,10 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parseImages: function ( json, onLoad ) {
 
-		var scope = this;
-		var images = {};
+		const scope = this;
+		const images = {};
+
+		let loader;
 
 		function loadImage( url ) {
 
@@ -546,15 +549,15 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		if ( json !== undefined && json.length > 0 ) {
 
-			var manager = new LoadingManager( onLoad );
+			const manager = new LoadingManager( onLoad );
 
-			var loader = new ImageLoader( manager );
+			loader = new ImageLoader( manager );
 			loader.setCrossOrigin( this.crossOrigin );
 
-			for ( var i = 0, il = json.length; i < il; i ++ ) {
+			for ( let i = 0, il = json.length; i < il; i ++ ) {
 
-				var image = json[ i ];
-				var url = image.url;
+				const image = json[ i ];
+				const url = image.url;
 
 				if ( Array.isArray( url ) ) {
 
@@ -562,11 +565,11 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 					images[ image.uuid ] = [];
 
-					for ( var j = 0, jl = url.length; j < jl; j ++ ) {
+					for ( let j = 0, jl = url.length; j < jl; j ++ ) {
 
-						var currentUrl = url[ j ];
+						const currentUrl = url[ j ];
 
-						var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
+						const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
 
 						images[ image.uuid ].push( loadImage( path ) );
 
@@ -576,7 +579,7 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 					// load single image
 
-					var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
+					const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
 
 					images[ image.uuid ] = loadImage( path );
 
@@ -602,13 +605,13 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		}
 
-		var textures = {};
+		const textures = {};
 
 		if ( json !== undefined ) {
 
-			for ( var i = 0, l = json.length; i < l; i ++ ) {
+			for ( let i = 0, l = json.length; i < l; i ++ ) {
 
-				var data = json[ i ];
+				const data = json[ i ];
 
 				if ( data.image === undefined ) {
 
@@ -622,7 +625,7 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				}
 
-				var texture;
+				let texture;
 
 				if ( Array.isArray( images[ data.image ] ) ) {
 
@@ -679,7 +682,7 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	parseObject: function ( data, geometries, materials ) {
 
-		var object;
+		let object;
 
 		function getGeometry( name ) {
 
@@ -699,11 +702,11 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			if ( Array.isArray( name ) ) {
 
-				var array = [];
+				const array = [];
 
-				for ( var i = 0, l = name.length; i < l; i ++ ) {
+				for ( let i = 0, l = name.length; i < l; i ++ ) {
 
-					var uuid = name[ i ];
+					const uuid = name[ i ];
 
 					if ( materials[ uuid ] === undefined ) {
 
@@ -729,6 +732,8 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		}
 
+		let geometry, material;
+
 		switch ( data.type ) {
 
 			case 'Scene':
@@ -830,8 +835,8 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			case 'Mesh':
 
-				var geometry = getGeometry( data.geometry );
-				var material = getMaterial( data.material );
+				geometry = getGeometry( data.geometry );
+				material = getMaterial( data.material );
 
 				object = new Mesh( geometry, material );
 
@@ -839,10 +844,10 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			case 'InstancedMesh':
 
-				var geometry = getGeometry( data.geometry );
-				var material = getMaterial( data.material );
-				var count = data.count;
-				var instanceMatrix = data.instanceMatrix;
+				geometry = getGeometry( data.geometry );
+				material = getMaterial( data.material );
+				const count = data.count;
+				const instanceMatrix = data.instanceMatrix;
 
 				object = new InstancedMesh( geometry, material, count );
 				object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
@@ -938,9 +943,9 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		if ( data.children !== undefined ) {
 
-			var children = data.children;
+			const children = data.children;
 
-			for ( var i = 0; i < children.length; i ++ ) {
+			for ( let i = 0; i < children.length; i ++ ) {
 
 				object.add( this.parseObject( children[ i ], geometries, materials ) );
 
@@ -952,12 +957,12 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
 
-			var levels = data.levels;
+			const levels = data.levels;
 
-			for ( var l = 0; l < levels.length; l ++ ) {
+			for ( let l = 0; l < levels.length; l ++ ) {
 
-				var level = levels[ l ];
-				var child = object.getObjectByProperty( 'uuid', level.object );
+				const level = levels[ l ];
+				const child = object.getObjectByProperty( 'uuid', level.object );
 
 				if ( child !== undefined ) {
 
@@ -975,7 +980,7 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 } );
 
-var TEXTURE_MAPPING = {
+const TEXTURE_MAPPING = {
 	UVMapping: UVMapping,
 	CubeReflectionMapping: CubeReflectionMapping,
 	CubeRefractionMapping: CubeRefractionMapping,
@@ -986,13 +991,13 @@ var TEXTURE_MAPPING = {
 	CubeUVRefractionMapping: CubeUVRefractionMapping
 };
 
-var TEXTURE_WRAPPING = {
+const TEXTURE_WRAPPING = {
 	RepeatWrapping: RepeatWrapping,
 	ClampToEdgeWrapping: ClampToEdgeWrapping,
 	MirroredRepeatWrapping: MirroredRepeatWrapping
 };
 
-var TEXTURE_FILTER = {
+const TEXTURE_FILTER = {
 	NearestFilter: NearestFilter,
 	NearestMipmapNearestFilter: NearestMipmapNearestFilter,
 	NearestMipmapLinearFilter: NearestMipmapLinearFilter,

+ 3 - 3
src/loaders/TextureLoader.js

@@ -19,9 +19,9 @@ TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		var texture = new Texture();
+		const texture = new Texture();
 
-		var loader = new ImageLoader( this.manager );
+		const loader = new ImageLoader( this.manager );
 		loader.setCrossOrigin( this.crossOrigin );
 		loader.setPath( this.path );
 
@@ -30,7 +30,7 @@ TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 			texture.image = image;
 
 			// JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
-			var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
+			const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
 
 			texture.format = isJPEG ? RGBFormat : RGBAFormat;
 			texture.needsUpdate = true;