#13362 closed bug (notabug)
jQuery.each() used to work on strings, but it doesn't in 1.9
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In jQuery 1.8.3 I could use .each() on a string and it would iterate over the characters in that string, but in 1.9 it fails with:
Uncaught TypeError: Cannot use 'in' operator to search for <x> in <y>
Where <x> is an index and <y> is a string.
The bug is in 'isArraylike()':
return type === "array" || type !== "function" && ( length === 0 || typeof length === "number" && length > 0 && ( length - 1 ) in obj );
It's the
(length - 1) in obj
that's the problem.
I'm not sure what the intention was with that check otherwise I'd submit a patch myself.
Change History (4)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
Strings aren't one of the supported types. http://api.jquery.com/jQuery.each/
comment:3 Changed 10 years ago by
Shouldn't it report that then? Instead of this obscure error? Cheers, Alex
comment:4 Changed 10 years ago by
Sorry but we're not getting into the business of checking all incoming args to see if someone passed invalid data, and then giving long descriptive error messages. Read the API documentation.
Oops, fogot jsFiddle link:
http://jsfiddle.net/HwxMX/