You bring up an interesting point Willi.
You stated that $() runs 2 times, which is correct, except that the first
time there is significantly more work being done. The first time it has to
search through the DOM collecting all the DOM elements and matching them
against the selector. This is a lot of work, but well worth it as you can
see. The results from the first pass are saved into an array. The second
pass only has to traverse the array which is a lot faster than the first
pass. Your idea would no doubt bring some speed improvements, but somewhat
breaks the concept of chainability, and the actual speed gained are minimal
at best.
I'll chew on the idea and see I can't think of similar speed ups that might
work the library model better. Thanks for your input.

~Sean

On 8/13/07, willi <[EMAIL PROTECTED]> wrote:
>
>
> Hallo,
>
> When the "search" $() returns a lot of objects (10000), then you have
> to loop twice through this objects. First for selecting the elements,
> and then second when doing somthing with the elements.
>
> e.g. $('td').addClass('red'); // get all tabledata and do something
> with them
>
> It would be nice if there were something when immediate when an
> element was found, a "callback" function can be executed. This can
> bring a lot of performance when handling a large amount of objects.
>
> $( expr, context ) // current
> $( expr, context, fn ) // possible add on to call a function
> immediately after it was found
>
> This may give developers the possiblity of using "Command Injection"
> and "Command Chaining" together.
>
> Thx & regards, Willi
>
> Thank's to all of you for building jQuery. It's realy one of the cool
> libraries where don't need a tree month course to start working with.
> Just use it to do your job. I like it also because you don't need to
> change your current web pages and jQuery fits to nearly every
> environment.
>
>

Reply via email to