Skip to main content

Bug Tracker

Side navigation

#11185 closed bug (patchwelcome)

Opened January 18, 2012 03:35AM UTC

Closed July 24, 2012 10:01PM UTC

isPlainObject gives wrong result in IE6/7/8 when constructor adds properties

Reported by: pcl Owned by:
Priority: low Milestone:
Component: core Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Test = function() { this.a = 1; }
alert($.isPlainObject(new Test()); // false in all browsers

Test.prototype = { b: 1 };

alert($.isPlainObject(new Test()); // true in IE6/7/8

"Own properties are enumerated firstly" is apparently not the case in these versions of IE, so the property added in the constructor gets tested instead of a prototype property.

A workaround is to do this instead:

Test.prototype = $.extend(Test.prototype, {b: 1});

Which ensures this earlier check passes:

!, "isPrototypeOf")

Attachments (0)
Change History (6)

Changed January 18, 2012 03:57AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

If it's created via a constructor function, it's not really a plain object. The documentation says this:

Check to see if an object is a plain object (created using "{}" or "new Object").

Changed January 18, 2012 04:03AM UTC by pcl comment:2

Replying to [comment:1 dmethvin]:

If it's created via a constructor function, it's not really a plain object.

Yes, the bug is that isPlainObject is returning true for what is not a plain object.

Changed January 18, 2012 04:04AM UTC by dmethvin comment:3

resolution: invalid
status: closedreopened

Oh hah! I read it backwards. Disregard, I suck ....

Changed March 10, 2012 02:09PM UTC by dmethvin comment:4

component: unfiledcore
milestone: None1.8
status: reopenedopen

Not sure this needs fixing, our use cases for isPlainObject don't require this level of differentiation. If it's easily fixable though, sure.

Changed May 18, 2012 01:28AM UTC by dmethvin comment:5

priority: undecidedlow

Changed July 24, 2012 10:01PM UTC by dmethvin comment:6

resolution: → patchwelcome
status: openclosed

Since this method is intended primarily for our internal use, it doesn't seem like it's worth fixing because it works for our needs. As an example, $.extend uses it, but we already know that constructed objects are impossible to handle there.

If there are some specific critical situations where this fails, or you have a simple fix, let us know.