Bug Tracker

Opened 12 years ago

Closed 12 years ago

#6919 closed enhancement (wontfix)

$.each looping over a string produces different results in IE8 Compatibility Mode

Reported by: bkorte Owned by:
Priority: low Milestone:
Component: traversing Version: 1.4.2
Keywords: each ie7 Cc: dmethvin
Blocked by: Blocking:


It's simplest to explain in code:



Safari 5.0.1 on OSX 10.6.4:

0 "s" 1 "t" 2 "r" 3 "i" 4 "n" 5 "g"

IE8 on Windows 7 running in Compatibility Mode (as well as IE7 mode chosen direct from the developer tools inspector):

LOG: 0undefined LOG: 1undefined LOG: 2undefined LOG: 3undefined LOG: 4undefined LOG: 5undefined

Simple workaround is:

c = (c === undefined) ? val.charAt(i) : c;

Expected result would be what Safari does.

Change History (7)

comment:1 Changed 12 years ago by bkorte

Forgot to mention this is running with 1.4.2.

comment:2 Changed 12 years ago by dmethvin

Resolution: invalid
Status: newclosed
Type: bugenhancement

The docs for jQuery.each say you should pass in a Javascript Object or Array, so a primitive string isn't a documented or supported argument there. Numbers, Booleans, Dates, null, and undefined are also not supported.

I'll recast this as an enhancement request but would vote against it because there are better ways to deal with strings and $.each is so widely used.

comment:3 Changed 12 years ago by dmethvin

Resolution: invalid
Status: closedreopened

comment:4 Changed 12 years ago by Rick Waldron

Cc: dmethvin added
Priority: undecided

Dave, can we clarify why this was reopened? If $.each is supposed to be "kind of" like forEach, then strings aren't supported. Additionally, like you even pointed out - nowhere in the docs does jQuery support strings.

Also, it missed the 1.4.3 milestone due date.

comment:5 Changed 12 years ago by Rick Waldron

Priority: undecidedlow

comment:6 Changed 12 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:7 Changed 12 years ago by snover

Resolution: wontfix
Status: reopenedclosed

If you want to iterate a string, use $.each(str.split(''), fn).

Note: See TracTickets for help on using tickets.