]> source.dussan.org Git - jquery.git/commitdiff
Explanations for each step of isPlainObject 1098/head
authorRick Waldron <waldron.rick@gmail.com>
Mon, 24 Dec 2012 15:54:11 +0000 (10:54 -0500)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 26 Dec 2012 18:34:38 +0000 (13:34 -0500)
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
src/core.js

index a89df3d4f0b1d79925f048ef0f517438d25ae6a3..41e68268e6d61c99ec3b252d006d490e846f63b0 100644 (file)
@@ -412,12 +412,17 @@ jQuery.extend({
        },
 
        isPlainObject: function( obj ) {
-               // Not plain objects: params that are not [[Class]] "[object Object]", DOM nodes, window
+               // Not plain objects:
+               // - Any object or value whose internal [[Class]] property is not "[object Object]"
+               // - DOM nodes
+               // - window
                if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
                        return false;
                }
 
                // Support: Firefox >16
+               // The try/catch supresses exceptions thrown when attempting to access
+               // the "constructor" property of certain host objects, ie. |window.location|
                try {
                        if ( obj.constructor &&
                                        !core_hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
@@ -427,6 +432,8 @@ jQuery.extend({
                        return false;
                }
 
+               // If the function hasn't returned already, we're confident that
+               // |obj| is a plain object, created by {} or constructed with new Object
                return true;
        },