Bug Tracker

Modify

Ticket #6919 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 3 years ago

$.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
Blocking: Blocked by:

Description

It's simplest to explain in code:

Given:

$.each('string',function(i,c){console.log(i,c);});

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

comment:1 Changed 3 years ago by bkorte

Forgot to mention this is running with 1.4.2.

comment:2 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Type changed from bug to enhancement
  • Resolution set to invalid

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 3 years ago by dmethvin

  • Status changed from closed to reopened
  • Resolution invalid deleted

comment:4 Changed 3 years ago by rwaldron

  • Cc dmethvin added
  • Priority set to 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 3 years ago by rwaldron

  • Priority changed from undecided to low

comment:6 Changed 3 years ago by snover

  • Milestone 1.4.3 deleted

Resetting milestone to future.

comment:7 Changed 3 years ago by snover

  • Status changed from reopened to closed
  • Resolution set to wontfix

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.