Since .get(-1) will be supported, eq(-1) would be supported too (?).
So your implementation needs some extra code:
eq: function( i ) {
if ( i < 0 )
i += this.length;
return this.pushStack( this[i], 'eq', i )
}
However this solution would be still faster then the one on
http://dev.jquery.com/ticket/4188, I suppose.
On Feb 26, 11:02 pm, ricardobeat <[email protected]> wrote:
> Right, thanks!
>
> Using pushStack seems ok, it's still chainable and keeps the selector
> state, while still being at least twice faster.
>
> http://dev.jquery.com/ticket/4262http://jquery.nodnod.net/cases/177/run
>
> cheers,
> - ricardo
>
> On Feb 26, 11:28 am, John Resig <[email protected]> wrote:
>
> > Well, first I would argue that the two are not equivalent.
>
> > $($(...)[x]) doesn't maintain the stack. You can no longer do:
> > $(...).eq(1).addClass("test").end().appendTo("#foo");
> > $($(...)[x]) doesn't maintain the internal selector state for plugins.
> > For example if you checked $(...).eq(1).selector you'd see: ".slice(1,
> > 2)"
>
> > So, with that in mind, if there were ways to maintain that
> > functionality and still get a performance speed-up, I'd definitely be
> > open to it.
>
> > --John
>
> > On Wed, Feb 25, 2009 at 11:41 PM, Ricardo Tomasi <[email protected]>
> > wrote:
>
> > > Creating two jQuery objects + a lookup $( $(...)[x] ) is faster than a
> > > simple $(...).eq(x). That doesn't make much sense.
>
> > > Currently the eq function looks like this:
> > > eq: function( i ) {
> > > return this.slice( i, +i + 1 );
> > > },
>
> > > Are there any downsides to changing it to this (object unique IDs,
> > > chaining)?
>
> > > eq: function( i ) {
> > > return jQuery(this[i]);
> > > },
>
> > > That offers a 25% to 40% speed improvement across all browsers.
> > >http://jquery.nodnod.net/cases/177
>
> > > cheers,
> > > - ricardo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---