Your solution resolves the "out of range" problem, but doesn't resolves the problem where el is not true. Although, jquery object is usually an array-like object of nodes, it can contains other values too, including: false, undefined, null and 0. In that cases your solution will return an "empty" jquery, instead of one with the wonted value.
On Mar 3, 2:03 am, ricardobeat <[email protected]> wrote: > Now this is getting dirty - this should do (split for readability): > > eq: function( i ) { > var el = this[ i<0 ? i+this.length : i]; > return this.pushStack( el || [], 'eq', i ) > > } > > No loss of performance with this one. > > - ricardo > > On Mar 2, 6:10 pm, Robert Katić <[email protected]> wrote: > > > I figured out (unfortunately not before) that the main reason why the > > current implementation uses slicing is to ensure correct behavior in > > case of "index out of range" and in case of !this[i]. > > Here proposed solutions will not return an empty jquery in that cases, > > but an jquery with the document element. > > > Maybe this would be more appropriate: > > > eq: function( i ) { > > return this.pushStack( i == -1 ? arraySlice.call(this, i) : > > arraySlice.call(this, i, +i + 1), 'eq', i ) > > > } > > > Unfortunately this looks dirty with no significant performance > > improvements in respect of the first solution I purposed > > onhttp://dev.jquery.com/ticket/4188. > > > Any better idea? > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
