Browse Source

Updated Object.assign() polyfill with the latest in MDN.

Mr.doob 9 years ago
parent
commit
4fddb139d2
1 changed files with 17 additions and 22 deletions
  1. 17 22
      src/Three.js

+ 17 - 22
src/Three.js

@@ -57,43 +57,36 @@ if ( Function.prototype.name === undefined && Object.defineProperty !== undefine
 
 if ( Object.assign === undefined ) {
 
+	// Missing in IE.
 	// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
 
-	Object.defineProperty( Object, 'assign', {
+	( function () {
 
-		writable: true,
-		configurable: true,
-
-		value: function ( target ) {
+		Object.assign = function ( target ) {
 
 			'use strict';
 
 			if ( target === undefined || target === null ) {
 
-				throw new TypeError( "Cannot convert first argument to object" );
+				throw new TypeError( 'Cannot convert undefined or null to object' );
 
 			}
 
-			var to = Object( target );
-
-			for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
+			var output = Object( target );
 
-				var nextSource = arguments[ i ];
+			for ( var index = 1; index < arguments.length; index ++ ) {
 
-				if ( nextSource === undefined || nextSource === null ) continue;
+				var source = arguments[ index ];
 
-				nextSource = Object( nextSource );
+				if ( source !== undefined && source !== null ) {
 
-				var keysArray = Object.keys( nextSource );
+					for ( var nextKey in source ) {
 
-				for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
+						if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
 
-					var nextKey = keysArray[ nextIndex ];
-					var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
+							output[ nextKey ] = source[ nextKey ];
 
-					if ( desc !== undefined && desc.enumerable ) {
-
-						to[ nextKey ] = nextSource[ nextKey ];
+						}
 
 					}
 
@@ -101,14 +94,16 @@ if ( Object.assign === undefined ) {
 
 			}
 
-			return to;
+			return output;
 
-		}
+		};
 
-	} );
+	} )();
 
 }
 
+//
+
 Object.assign( THREE, {
 
 	// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button