Explorar o código

Core: Convert to es6 class.

linbingquan %!s(int64=5) %!d(string=hai) anos
pai
achega
d726694348
Modificáronse 2 ficheiros con 31 adicións e 32 borrados
  1. 16 17
      src/core/Clock.js
  2. 15 15
      src/core/Face3.js

+ 16 - 17
src/core/Clock.js

@@ -1,18 +1,18 @@
-function Clock( autoStart ) {
+class Clock {
 
-	this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
+	constructor( autoStart ) {
 
-	this.startTime = 0;
-	this.oldTime = 0;
-	this.elapsedTime = 0;
+		this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
 
-	this.running = false;
+		this.startTime = 0;
+		this.oldTime = 0;
+		this.elapsedTime = 0;
 
-}
+		this.running = false;
 
-Object.assign( Clock.prototype, {
+	}
 
-	start: function () {
+	start() {
 
 		this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
 
@@ -20,24 +20,24 @@ Object.assign( Clock.prototype, {
 		this.elapsedTime = 0;
 		this.running = true;
 
-	},
+	}
 
-	stop: function () {
+	stop() {
 
 		this.getElapsedTime();
 		this.running = false;
 		this.autoStart = false;
 
-	},
+	}
 
-	getElapsedTime: function () {
+	getElapsedTime() {
 
 		this.getDelta();
 		return this.elapsedTime;
 
-	},
+	}
 
-	getDelta: function () {
+	getDelta() {
 
 		let diff = 0;
 
@@ -63,7 +63,6 @@ Object.assign( Clock.prototype, {
 
 	}
 
-} );
-
+}
 
 export { Clock };

+ 15 - 15
src/core/Face3.js

@@ -1,31 +1,31 @@
 import { Color } from '../math/Color.js';
 import { Vector3 } from '../math/Vector3.js';
 
-function Face3( a, b, c, normal, color, materialIndex ) {
+class Face3 {
 
-	this.a = a;
-	this.b = b;
-	this.c = c;
+	constructor( a, b, c, normal, color, materialIndex ) {
 
-	this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
-	this.vertexNormals = Array.isArray( normal ) ? normal : [];
+		this.a = a;
+		this.b = b;
+		this.c = c;
 
-	this.color = ( color && color.isColor ) ? color : new Color();
-	this.vertexColors = Array.isArray( color ) ? color : [];
+		this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
+		this.vertexNormals = Array.isArray( normal ) ? normal : [];
 
-	this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
+		this.color = ( color && color.isColor ) ? color : new Color();
+		this.vertexColors = Array.isArray( color ) ? color : [];
 
-}
+		this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
 
-Object.assign( Face3.prototype, {
+	}
 
-	clone: function () {
+	clone() {
 
 		return new this.constructor().copy( this );
 
-	},
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
 		this.a = source.a;
 		this.b = source.b;
@@ -52,7 +52,7 @@ Object.assign( Face3.prototype, {
 
 	}
 
-} );
+}
 
 
 export { Face3 };