Ticket #6125 (closed bug: wontfix)
Unfiltered for loop breaks animation in IE when a script extends the Object prototype
| Reported by: | willmorgan | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.2 |
| Component: | effects | Version: | 1.4.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I've added a function called size() to the Object prototype for getting the size of objects.
I noticed this broke animation in general, so commented out each module of my code until I found the source of the problem, which was the above.
I've got a fix, which is simply filtering the for loop on line 2724 where Sizzle.filter is defined:
if ( Expr.filter.hasOwnProperty( type ) ) {
As expected this doesn't cause a problem in Firefox ;)
Attachments
Change History
Changed 3 years ago by willmorgan
-
attachment
6125.rar
added
Patched version of jQuery and test page that works correctly.
comment:1 follow-up: ↓ 2 Changed 3 years ago by snover
- Priority set to undecided
- Status changed from new to closed
- Resolution set to wontfix
Modifying Object.prototype is verboten.
comment:2 in reply to: ↑ 1 Changed 3 years ago by willmorgan
Replying to snover:
Modifying Object.prototype is verboten.
Why? Is that not how the entire idea of inheritance works in JavaScript?
comment:3 Changed 3 years ago by ajpiano
No, it is not. It is fine to work with prototypes of various objects, but it is considered very poor practise to modify Object.protoype.
comment:4 Changed 3 years ago by willmorgan
Surely bulletproofing jQuery's code is a good idea, regardless of whether this is considered bad practice or not.
comment:5 Changed 3 years ago by ajpiano
This has come up before: #1529, #2721, #3785, #4121, #6132
Consistently jQuery's position has been, as Dave stated in #3785, that "Rewriting every for/in loop and object membership test is just too expensive." Until such time that the position should happen to change on that matter, jQuery will not work in pages that have modifications to Object.prototype.
comment:6 Changed 3 years ago by willmorgan
I would agree that consistency is probably the best thing, though in fact, I've seen a few posts from John and Scott in the past saying that bulletproofing jQuery might be on the cards for future releases.
My £0.02 is that a widely used framework should be as portable and bulletproof as possible, and that there are arguments against extending the Object prototype and also not filtering for loops.. I've not seen any too much in depth discussion regarding the issue specific to jQuery, but if that's what the core team goes with, then fair enough.
Thanks for your time - I can imagine it's quite frustrating having closed many duplicates in the past hence the initial terseness (albeit 9 months later...)
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Test case document