Skip to main content

Bug Tracker

Side navigation

#10458 closed bug (wontfix)

Opened October 09, 2011 06:49AM UTC

Closed October 09, 2011 02:31PM UTC

Last modified April 06, 2013 09:50AM UTC

jQuery.isPlainObject() always returns false when Object.prototype has a properties

Reported by: vovan-ve@yandex.ru Owned by:
Priority: low Milestone: None
Component: core Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:
Description

jQuery.isPlainObject() finally enumerates all propertyes of an object. If the last property is own, then function relies that it is an Object. As the result, it is not allowed to have any properties in prototype. So, if we extend Object.prototype with at least one property, jQuery.isPlainObject() will always return false for new objects, created after.

jsFiddle: http://jsfiddle.net/kqe95/

alert(jQuery.isPlainObject({})); // true
Object.prototype.foo = function(){};
alert(jQuery.isPlainObject({})); // false
Attachments (0)
Change History (10)

Changed October 09, 2011 02:31PM UTC by rwaldron comment:1

component: unfiledcore
priority: undecidedlow
resolution: → wontfix
status: newclosed

Changed April 03, 2013 07:18PM UTC by laurentiu.macovei@dotnetwise.com comment:2

This is still not fixed!

Besides the function does a lot of "stuff" and its performance is very low!

It is extensively used by $.extend when creating deep copies!

Why not simply comparing either object.__proto__ == Object.prototype or in IE Object.getPrototypeOf(object) == Object.prototype

if Object.getPrototypeOf is missing as well, the current implementation could be good enough

Tests are here: http://jsfiddle.net/LLKET/1/

Changed April 03, 2013 11:02PM UTC by rwaldron comment:3

Right... it's not fixed because I closed it as "won't fix", because jQuery won't fix bugs that are caused by user code that does stupid things like extending Object.prototype

Changed April 04, 2013 11:32AM UTC by vovan-ve comment:4

Replying to [comment:3 rwaldron]:

... user code that does stupid things like extending Object.prototype

I still think, that You are not right. Can you give a prooflink to confirm this words?

Changed April 04, 2013 01:15PM UTC by laurentiu.macovei@dotnetwise.com comment:5

Why my above approach is not a good fix for all modern browsers?

Changed April 04, 2013 01:44PM UTC by vovan-ve comment:6

Replying to [comment:5 laurentiu.macovei@…]:

Why my above approach is not a good fix for all modern browsers?

1. http://jsfiddle.net/FdSwc/

function Foo() {};
Foo.prototype = Object.prototype;
alert( new Foo().__proto__ === Object.prototype );

2. one_window.Object !== another_window.Object;

/* this is window A */
window.FooBar = {};
open('<url to run next code in B>');

/* this is window B opened by window.open() in A */
alert( opener.Object === Object ); // false
alert( opener.FooBar.__proto__ === Object.prototype ); // false
alert( opener.FooBar.__proto__ === opener.Object.prototype ); // true

Changed April 05, 2013 10:21AM UTC by laurentiu.macovei@dotnetwise.com comment:7

That's correct but I think you really don't care about that. It may be useful in 0.001% of cases, whereas you could use the current option.

Changed April 05, 2013 03:03PM UTC by rwaldron comment:8

Replying to [comment:4 vovan-ve]:

Replying to [comment:3 rwaldron]: > ... user code that does stupid things like extending Object.prototype I still think, that You are not right. Can you give a prooflink to confirm this words?

jQuery's Won't Fix: http://contribute.jquery.org/wont-fix/

The problem with adding properties to Object.prototype is that all Object's will then inherit those properties, whether they want to or not—and these properties will appear in for-in loops.

Since ES5, Object.prototype can be safely augmented with Object.definePropert(y|ies) by creating a properties and specifying that its [[enumerable]] field is false.

Changed April 05, 2013 04:30PM UTC by anonymous comment:9

Replying to [comment:8 rwaldron]:

Replying to [comment:4 vovan-ve]: - "Object.prototype is verboten" http://erik.eae.net/archives/2005/06/06/22.13.54/ ...

Thanks for the links. Now I see I'm not right.

Changed April 06, 2013 09:50AM UTC by DotNetWise comment:10

Even so, jQuery will simply fail when Object.prototype will have something added.

But that can be sorted out with ES5 Object.defineProperty("someProperty", { enumerable: false});