Bug Tracker

Opened 8 years ago

Closed 8 years ago

#7686 closed enhancement (invalid)

For loop should be changed to while loop

Reported by: nick@… Owned by: nick@…
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

Line 612 of core.js in $.each();

for ( ; i < length; ) { could be better written as while ( i < length ) {

It is less confusing, and even faster in some browsers according to http://jsperf.com/loops-while-vs-for/7.

I have made the change here: https://github.com/ncammarata/jquery/commit/4c1f406ec829986c65ba40b9fb44548fe3ed88e8

First bug report, I hope I did this correctly.

Change History (2)

comment:1 Changed 8 years ago by Rick Waldron

Owner: set to nick@…
Status: newpending

I'm getting almost identical results in Chrome.

comment:2 Changed 8 years ago by snover

Resolution: invalid
Status: pendingclosed

Thanks for the report, but this is not a valid enhancement. That jsperf test is invalid; you are failing to reset the iterator between tests. Properly resetting the iterator value between tests, such as in this test, shows that the two loop structures function identically.

Note: See TracTickets for help on using tickets.