Skip to content

Commit 3746bf8

Browse files
committed
Explanations for each step of isPlainObject
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
1 parent 7e3f96c commit 3746bf8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,17 @@ jQuery.extend({
412412
},
413413

414414
isPlainObject: function( obj ) {
415-
// Not plain objects: params that are not [[Class]] "[object Object]", DOM nodes, window
415+
// Not plain objects:
416+
// - Any object or value whose internal [[Class]] property is not "[object Object]"
417+
// - DOM nodes
418+
// - window
416419
if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
417420
return false;
418421
}
419422

420423
// Support: Firefox >16
424+
// The try/catch supresses exceptions thrown when attempting to access
425+
// the "constructor" property of certain host objects, ie. |window.location|
421426
try {
422427
if ( obj.constructor &&
423428
!core_hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
@@ -427,6 +432,8 @@ jQuery.extend({
427432
return false;
428433
}
429434

435+
// If the function hasn't returned already, we're confident that
436+
// |obj| is a plain object, created by {} or constructed with new Object
430437
return true;
431438
},
432439

0 commit comments

Comments
 (0)