#5302 closed bug (wontfix)
$.each fails on certain objects containing a property-key "length"
Reported by: | Marc Jansen | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | core | Version: | 1.3.2 |
Keywords: | Cc: | Marc, Jansen | |
Blocked by: | Blocking: |
Description
when $.each is called with an object, that has an attribute named length, it does not iterate over the object:
var humpty = { 'length' : 'foobar' }; $.each(humpty, function (i, n) { alert('$.each: ' + i); });
Using the traditional for-in-way it works:
for( objKey in humpty ) { alert('for in: ' + objKey); }
In the function it is only tested whether length is not equal to undefined.
The function should check the nature of the object to iterate over differently:
perhaps: iterObj.constructor === Object iterObj.constructor === Array
Change History (3)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Cc: | Marc Jansen added |
---|---|
Component: | unfilled → core |
Resolution: | → wontfix |
Status: | new → closed |
This is the desired behavior. You can always write your iterator function that works differently.
comment:3 Changed 13 years ago by
I really don't see why this would be desired behavior. Just in case this is reopened some day, this is my patch:
http://github.com/steadicat/jquery/commit/8d7948ad5417695af41d8be9851a4f85021a7b3c
Sorry, the last line should read