Bug Tracker

Ticket #3520 (closed bug: duplicate)

Opened 6 years ago

Last modified 6 years ago

.eq(n) acts funny

Reported by: sorpigal Owned by:
Priority: minor Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: sorpigal, flesler
Blocking: Blocked by:

Description

When passing .eq() a variable containing an integer parsed out of a string the results are strange. In my case I was passing 0, 1 or 2 based on the values found in a string. When passing 0 and 2 I got expected results, when passing 1 I found that .eq(n).length == 2, which is very wrong.

I do not have a simple test case for this, but the fix is:

eq: function( i ) {

return this.slice( +i, +i + 1 );

},

The unary + forces i to be a number. I think there is no possible harm to this and it will save many people frustration. Technically, of course, it is user error.

Change History

comment:1 Changed 6 years ago by flesler

  • Cc sorpigal, flesler added

This should be fixed in trunk.

Can you try with this file ?  http://code.jquery.com/jquery-nightly.js

Do post back even if it works so that I can close this.

comment:2 Changed 6 years ago by flesler

If you're interested: #3102

comment:3 Changed 6 years ago by sorpigal

Confirmed, works as expected with nightly.

Sorry, if I had known about that I would have tested before filing.

comment:4 Changed 6 years ago by flesler

  • Status changed from new to closed
  • Resolution set to duplicate

No problem.

Note: See TracTickets for help on using tickets.