Browse Source

THREE.extend improvements: adopt safe {}.hasOwnProperty method source. Optimize Object.keys() based on @paulmillr suggestion.

Ben Houston 12 years ago
parent
commit
53169124d9
1 changed files with 11 additions and 6 deletions
  1. 11 6
      src/Three.js

+ 11 - 6
src/Three.js

@@ -51,18 +51,23 @@ THREE.extend = function ( obj, source ) {
 	// ECMAScript5 compatibility based on: http://www.nczonline.net/blog/2012/12/11/are-your-mixins-ecmascript-5-compatible/
 	if ( Object.keys ) {
 
-        Object.keys( source ).forEach( 
-			function ( prop ) {
-					Object.defineProperty( obj, prop, Object.getOwnPropertyDescriptor( source, prop ) );
-				}
-			);
+		var keys = Object.keys( source );
+
+		for (var i = 0, il = keys.length; i < il; i++) {
+
+			var prop = keys[i];
+			Object.defineProperty( obj, prop, Object.getOwnPropertyDescriptor( source, prop ) );
+
+		}
 
     }
     else {
 
+		var safeHasOwnProperty = {}.hasOwnProperty;
+
 		for ( var prop in source ) {
 
-			if ( source.hasOwnProperty( prop ) ) {
+			if ( safeHasOwnProperty.call( source, prop ) ) {
 
 				obj[prop] = source[prop];