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: | 1.next |
Component: | core | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
#!js 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:
#!js Test.prototype = $.extend(Test.prototype, {b: 1});
Which ensures this earlier check passes:
#!js !hasOwn.call(obj.constructor.prototype, "isPrototypeOf")
Attachments (0)
Change History (6)
Changed January 18, 2012 03:57AM UTC by comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
Changed January 18, 2012 04:03AM UTC by 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 comment:3
resolution: | invalid |
---|---|
status: | closed → reopened |
Oh hah! I read it backwards. Disregard, I suck ....
Changed March 10, 2012 02:09PM UTC by comment:4
component: | unfiled → core |
---|---|
milestone: | None → 1.8 |
status: | reopened → open |
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 comment:5
milestone: | 1.8 → 1.next |
---|---|
priority: | undecided → low |
Changed July 24, 2012 10:01PM UTC by comment:6
resolution: | → patchwelcome |
---|---|
status: | open → closed |
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.
If it's created via a constructor function, it's not really a plain object. The documentation says this:
http://api.jquery.com/jQuery.isPlainObject/