Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#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:


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 Marc Jansen

Sorry, the last line should read

// perhaps: 
iterObj.constructor === Object 
iterObj.constructor === Array 

comment:2 Changed 13 years ago by flesler

Cc: Marc Jansen added
Component: unfilledcore
Resolution: wontfix
Status: newclosed

This is the desired behavior. You can always write your iterator function that works differently.

comment:3 Changed 13 years ago by steadicat

I really don't see why this would be desired behavior. Just in case this is reopened some day, this is my patch:


Note: See TracTickets for help on using tickets.