Ticket #7780 (closed bug: worksforme)
$.isPlainObject inconsistent
| Reported by: | rwaldron | Owned by: | rwaldron |
|---|---|---|---|
| Priority: | high | Milestone: | 1.6 |
| Component: | core | Version: | 1.4.4 |
| Keywords: | neededdocs | Cc: | |
| Blocking: | Blocked by: |
Description
As documented in this fiddle, $.isPlainObject() is evaluating inconsistently across browsers.
Change History
comment:1 Changed 3 years ago by rwaldron
- Owner set to rwaldron
- Priority changed from undecided to high
- Status changed from new to assigned
- Component changed from unfiled to core
comment:3 Changed 3 years ago by rwaldron
- Keywords needsdocs added
- Status changed from assigned to closed
- Resolution set to wontfix
comment:4 Changed 3 years ago by rwaldron
- Status changed from closed to reopened
- Resolution wontfix deleted
comment:5 Changed 2 years ago by dmethvin
I thought we accepted that host objects might break this way, kind of like how we don't support $.isFunction(window.alert). Or is the needsdocs here just to say we need to document that fact?
comment:6 Changed 2 years ago by rwaldron
- Status changed from reopened to closed
- Resolution set to worksforme
Dave, yes - there are too many host objects that have too many inconsistencies for the library to robustly feature detect (without adding garbage regular expressions) - the needsdocs tag is to document this.
comment:7 Changed 2 years ago by shane@…
isPlainObject: function( obj ) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
return false;
}
// Not own constructor property must be Object
if ( obj.constructor &&
!hasOwn.call(obj, "constructor") &&
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
var key;
for ( key in obj ) {
if(!hasOwn.call( obj, key )){
return false;
}
}
return key === undefined;
}
comment:8 Changed 2 years ago by addyosmani
- Keywords neededdocs added; needsdocs removed
Documentation updated: http://api.jquery.com/jQuery.isPlainObject/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Initially reported by jaubourg here: #7743