I disagree. Calling $$ twice on the same selector is not very efficient.
Whenever possible, only call $$ once. $ is much less forgiving on speed.
Calling either $$ or $ on a collection of elements or a single element
(respectively) has no cost. So:
var el = $(id);
$(el).whatever() //no expense
$(id); //cheaper than the first time and but slightly more costly

var els = $$(selector);
$$(els).whatever() //no expense
$$(selector); //nearly as expensive as the first time

On Tue, Oct 7, 2008 at 2:13 PM, Nathan White <
[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> wrote:

> Your code snippet is the best approach.
>
> Mootools is fast at retrieving elements that have already been 'touched'.
> The biggest culprit in performance is the DOM traversal.
>
>
> On Tue, Oct 7, 2008 at 5:06 PM, Michael Duff <[EMAIL 
> PROTECTED]<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=1304791&i=0>
> > wrote:
>
>>
>> Hey Everyone,
>>
>> I have a question about coding style, I will be using the same "items"
>> over and over throughout a class I am writing, so would it be better
>> to place these items in an array for later use?
>>
>>
>> $$('.someclass').each(function(item, index) {
>>        this.items[] = item;
>> });
>>
>>
>> then anytime I need to loop through them I can just use this.items
>> instead of $$, does anyone know if its more expensive to store
>> references to those items or for mootools to go find them each time?
>>
>> Mike
>>
>>
>
>
> ------------------------------
>  View message @
> http://n2.nabble.com/cheaper-to-use-array-or-%24%24%28%29-tp1304776p1304791.html
> To start a new topic under MooTools Users, email
> [EMAIL PROTECTED]<[EMAIL PROTECTED]>
> To unsubscribe from MooTools Users, click here< (link removed) >.
>
>
>


-----
The MooTools Tutorial:  http://www.mootorial.com www.mootorial.com 
CNET Clientside:  http://clientside.cnet.com clientside.cnet.com 
-- 
View this message in context: 
http://n2.nabble.com/cheaper-to-use-array-or-%24%24%28%29-tp1304776p1304802.html
Sent from the MooTools Users mailing list archive at Nabble.com.

Reply via email to