views:

34

answers:

1

It doesn't in FF/Chrome and I don't think it should in IE. after all $() doesn't return a plain object, but an instance of $. Am I wrong?

+5  A: 

Short Answer: no, you're not crazy, it is indeed a bug in jQuery core.


Long Answer:

I setup a quick test to see what the difference is here: http://jsfiddle.net/nick_craver/9J3VP/

The property list differs in it's order in IE (8 at least), so this part (from jQuery core):

var key;
for ( key in obj ) { }

It grabbing the last property in the list and doing a hasOwnProperty check on it, so it's boiling down to this in IE:

Object.prototype.hasOwnProperty.call($(document.body), 'length') //true

and this in other browsers (tested FF/Chrome):

Object.prototype.hasOwnProperty.call($(document.body), 'width') //false

Since that property list is ordered differently, it's grabbing the length property in IE, and something else in other browsers, we're getting a different result (for kicks, click to include jQuery UI on the left, watch it change to another custom property, tabs). This comment above the for loop:

// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.

Is a false assumption about IE's property ordering, so I'd consider this a bug as of jQuery 1.4.2.

Nick Craver