Ticket #13021 (closed feature: fixed)
each() cannot work well with a literal object who has a length member
| Reported by: | ZengWq572 | Owned by: | gibson042 |
|---|---|---|---|
| Priority: | low | Milestone: | 1.9 |
| Component: | core | Version: | 1.8.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
if i have a literal object:
var objWithLength =[[BR]]
length: 2,[[BR]]
a: 1[[BR]]
};
jQuery.each(objWithLength, function(key, value){[[BR]]
alert(key + ', ' + value);[[BR]]
});[[BR]]
the each() function cannot work as what i want.
i read the source of jQuery, the each(obj, ...) function only checks 'obj.length' attribute and isFunction(obj). Do you do this for purpose?
if i have the honor, i hope you can sent me an reply.
thank you!
Change History
comment:2 Changed 5 months ago by gibson042
- Status changed from new to assigned
- Component changed from unfiled to core
- Priority changed from undecided to low
- Milestone changed from None to 1.9
- Owner set to gibson042
- Type changed from bug to feature
This may get marked wontfix, but there is still a little bit of wiggle room here.
comment:3 Changed 5 months ago by Rick Waldron
- Status changed from assigned to closed
- Resolution set to fixed
Fixes #13021. Normalization of core utility array like detection based on standard protocol by Richard Gibson <richard.gibson@…>. Closes gh-1064
Changeset: 07a7b3e4cf961e51bddcdb90cdca34f9126ed286
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

if i have a literal object with length attribute, the each() function cannot work well as what i want. For example:
var objWithLength = { length: 2, a: 1 }; jQuery.each(objWithLength, function(key, value){ alert(key + ': ' + value); });the each() function will alert out ''1: undefined'' and ''2: undefined''.
i read the source of jQuery, the each(obj, ...) function only checks 'obj.length' attribute and isFunction(obj). Do you do this for purpose?
if i have the honor, i hope you can sent me an reply.
thank you!