Have you considered using a flyweight object?
It's about seven times faster in FF3.5 than creating a new jQuery
object on every iteration:

var el = document.body;
var t = new Date;
for(var i=0;i<10000;i++)
$(el);
console.log(new Date - t);

var $fly = $();
var t = new Date;
for(var i=0;i<10000;i++)
$fly[0] = el;
console.log(new Date - t);

And you can still make it a proper jQuery object by calling $( $fly )
inside the callback function, so that it can be referenced afterwards.

Moreover, in this case it would be unnecessary to use `this.setArray
( jQuery.makeArray(selector) )` in the `init` method, you could just
check if it's a flyweight object and simply create a new object with
the element.

On Jul 22, 12:49 pm, Ricardo <ricardob...@gmail.com> wrote:
> This seems pointless to me. You can create a new jQ object from 'this'
> anytime you want - and only when you want, avoiding the overhead.
> Would be useful if $this referred to the whole collection being
> iterated, not the current element in the loop.
>
> cheers
> ricardo
>
> On Jul 21, 12:14 am, Yehuda Katz <wyc...@gmail.com> wrote:
>
>
>
> > At the moment, traversal callbacks, like the ones passed to find/filter/etc.
> > take a single "index" parameter. I'd like to propose that they are unified
> > with .each as follows:
> > $("div").filter(function(i, self) {
> >   // stuff
>
> > });
>
> > As a separate concern, I'd like to discuss changing the second parameter in
> > both to be a jQuery object. Obviously, it would need to be done via slow
> > deprecation for .each, but I don't think it'd break all that much code:
>
> > $("div").filter(function(i, self) {
> >   // self == $(this)
>
> > })
>
> > Thoughts?
>
> > --
> > Yehuda Katz
> > Developer | Engine Yard
> > (ph) 718.877.1325
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to