Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

Javascript: optimize loops

Hi,

I was just reading these posts:

http://jonraasch.com/blog/10-javascript-performance-boosting-tips-from-nicholas-zakas
http://www.nczonline.net/blog/2009/01/13/speed-up-your-javascript-part-1/

In particular, my question alludes to the second post from nczonline.net. Supposedly, this function that Zakas, the author created will give a boost in performance in loops:

function chunk(array, process, context){
    setTimeout(function(){
        var item = array.shift();
        process.call(context, item);

        if (array.length > 0){
            setTimeout(arguments.callee, 100);
        }
    }, 100);
}

Open in new window


Two questions:
1) I'm wondering they there is a timer set to 100ms. Doesn't that slow down the execution?

2) What is the arguments.callee? What object is the arguments from?

Much thanks.
SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor Kimura

ASKER

Oh, I see. Thanks, AlexCode! Makes sense now. =)

Just wondering now regarding the second question:

2) What is the arguments.callee? What object is the arguments from?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I get it. Thank you so much for the clear and thorough answers, Alex! =)
I highly recommend the following book:
High Performance Javascript

Shortly my website will be online and you'll have a lot of resources on this subject also.

Cheers!
That's great, Alex. I'm looking forward to your site and updates on them. Keep me posted on your site. =)