瀏覽代碼

Material: Move to let/const.

Mugen87 5 年之前
父節點
當前提交
e1f99e839d
共有 2 個文件被更改,包括 24 次插入21 次删除
  1. 18 15
      src/materials/Material.js
  2. 6 6
      src/materials/ShaderMaterial.js

+ 18 - 15
src/materials/Material.js

@@ -7,7 +7,7 @@ import { MathUtils } from '../math/MathUtils.js';
  * @author alteredq / http://alteredqualia.com/
  */
 
-var materialId = 0;
+let materialId = 0;
 
 function Material() {
 
@@ -89,9 +89,9 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 		if ( values === undefined ) return;
 
-		for ( var key in values ) {
+		for ( const key in values ) {
 
-			var newValue = values[ key ];
+			const newValue = values[ key ];
 
 			if ( newValue === undefined ) {
 
@@ -109,7 +109,7 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 			}
 
-			var currentValue = this[ key ];
+			const currentValue = this[ key ];
 
 			if ( currentValue === undefined ) {
 
@@ -138,7 +138,7 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 	toJSON: function ( meta ) {
 
-		var isRoot = ( meta === undefined || typeof meta === 'string' );
+		const isRoot = ( meta === undefined || typeof meta === 'string' );
 
 		if ( isRoot ) {
 
@@ -149,7 +149,7 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 		}
 
-		var data = {
+		const data = {
 			metadata: {
 				version: 4.5,
 				type: 'Material',
@@ -314,11 +314,11 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 		function extractFromCache( cache ) {
 
-			var values = [];
+			const values = [];
 
-			for ( var key in cache ) {
+			for ( const key in cache ) {
 
-				var data = cache[ key ];
+				const data = cache[ key ];
 				delete data.metadata;
 				values.push( data );
 
@@ -330,8 +330,8 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 		if ( isRoot ) {
 
-			var textures = extractFromCache( meta.textures );
-			var images = extractFromCache( meta.images );
+			const textures = extractFromCache( meta.textures );
+			const images = extractFromCache( meta.images );
 
 			if ( textures.length > 0 ) data.textures = textures;
 			if ( images.length > 0 ) data.images = images;
@@ -382,17 +382,20 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 		this.stencilZPass = source.stencilZPass;
 		this.stencilWrite = source.stencilWrite;
 
-		var srcPlanes = source.clippingPlanes,
-			dstPlanes = null;
+		const srcPlanes = source.clippingPlanes;
+		let dstPlanes = null;
 
 		if ( srcPlanes !== null ) {
 
-			var n = srcPlanes.length;
+			const n = srcPlanes.length;
 			dstPlanes = new Array( n );
 
-			for ( var i = 0; i !== n; ++ i )
+			for ( let i = 0; i !== n; ++ i ) {
+
 				dstPlanes[ i ] = srcPlanes[ i ].clone();
 
+			}
+
 		}
 
 		this.clippingPlanes = dstPlanes;

+ 6 - 6
src/materials/ShaderMaterial.js

@@ -117,14 +117,14 @@ ShaderMaterial.prototype.copy = function ( source ) {
 
 ShaderMaterial.prototype.toJSON = function ( meta ) {
 
-	var data = Material.prototype.toJSON.call( this, meta );
+	const data = Material.prototype.toJSON.call( this, meta );
 
 	data.uniforms = {};
 
-	for ( var name in this.uniforms ) {
+	for ( const name in this.uniforms ) {
 
-		var uniform = this.uniforms[ name ];
-		var value = uniform.value;
+		const uniform = this.uniforms[ name ];
+		const value = uniform.value;
 
 		if ( value && value.isTexture ) {
 
@@ -192,9 +192,9 @@ ShaderMaterial.prototype.toJSON = function ( meta ) {
 	data.vertexShader = this.vertexShader;
 	data.fragmentShader = this.fragmentShader;
 
-	var extensions = {};
+	const extensions = {};
 
-	for ( var key in this.extensions ) {
+	for ( const key in this.extensions ) {
 
 		if ( this.extensions[ key ] === true ) extensions[ key ] = true;