Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made isObjectLiteral to work correctly with custom objects with empty…

… prototypes.
  • Loading branch information...
commit 990d9ca1b05a587cce7599a1a40aa2558117db41 1 parent 1ce92e0
Robert Katić authored November 12, 2009 jeresig committed November 12, 2009
11  src/core.js
@@ -328,13 +328,20 @@ jQuery.extend({
328 328
 			return false;
329 329
 		}
330 330
 		
  331
+		// not own constructor property must be Object
  332
+		if ( obj.constructor
  333
+		  && !hasOwnProperty.call(obj, "constructor")
  334
+		  && !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) {
  335
+			return false;
  336
+		}
  337
+		
331 338
 		//own properties are iterated firstly,
332 339
 		//so to speed up, we can test last one if it is own or not
333  
-		
  340
+	
334 341
 		var key;
335 342
 		for ( key in obj ) {}
336 343
 		
337  
-		return !key || hasOwnProperty.call( obj, key );
  344
+		return key === undefined || hasOwnProperty.call( obj, key );
338 345
 	},
339 346
 
340 347
 	isEmptyObject: function( obj ) {
6  test/unit/core.js
@@ -553,10 +553,14 @@ test("jQuery.extend(Object, Object)", function() {
553 553
 	same( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
554 554
 
555 555
 	var myKlass = function() {};
  556
+	var optionsWithCustomObject = { foo: { date: new myKlass } };
  557
+	empty = {};
  558
+	jQuery.extend(true, empty, optionsWithCustomObject);
  559
+	same( empty.foo, optionsWithCustomObject.foo, "Custom objects copy correctly (no methods)" );
  560
+	
556 561
 	// Makes the class a little more realistic
557 562
 	myKlass.prototype = { someMethod: function(){} };
558 563
 	empty = {};
559  
-	var optionsWithCustomObject = { foo: { date: new myKlass } };
560 564
 	jQuery.extend(true, empty, optionsWithCustomObject);
561 565
 	same( empty.foo, optionsWithCustomObject.foo, "Custom objects copy correctly" );
562 566
 

0 notes on commit 990d9ca

Please sign in to comment.
Something went wrong with that request. Please try again.