Browse Source

Merge pull request #21231 from DefinitelyMaybe/light.js

src/lights: light.js -> es6 classes
Mr.doob 4 years ago
parent
commit
3d82b58555
1 changed files with 14 additions and 17 deletions
  1. 14 17
      src/lights/Light.js

+ 14 - 17
src/lights/Light.js

@@ -1,37 +1,34 @@
 import { Object3D } from '../core/Object3D.js';
 import { Color } from '../math/Color.js';
 
-function Light( color, intensity = 1 ) {
+class Light extends Object3D {
 
-	Object3D.call( this );
+	constructor( color, intensity = 1 ) {
 
-	this.type = 'Light';
+		super( );
 
-	this.color = new Color( color );
-	this.intensity = intensity;
+		this.type = 'Light';
 
-}
-
-Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
-
-	constructor: Light,
+		this.color = new Color( color );
+		this.intensity = intensity;
+		Object.defineProperty( this, 'isLight', { value: true } );
 
-	isLight: true,
+	}
 
-	copy: function ( source ) {
+	copy( source ) {
 
-		Object3D.prototype.copy.call( this, source );
+		super.copy( source );
 
 		this.color.copy( source.color );
 		this.intensity = source.intensity;
 
 		return this;
 
-	},
+	}
 
-	toJSON: function ( meta ) {
+	toJSON( meta ) {
 
-		const data = Object3D.prototype.toJSON.call( this, meta );
+		const data = super.toJSON( meta );
 
 		data.object.color = this.color.getHex();
 		data.object.intensity = this.intensity;
@@ -49,7 +46,7 @@ Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	}
 
-} );
+}
 
 
 export { Light };