The order of elements in a simple array like this is guaranteed.
Looping over an object with a for in loop, the order is not
guaranteed, though by convention most browsers honor the order in
which the elements were added. jQuery would have to go out of its way
to return the elements from your array in a different order. So, yes,
you can count on the order being correct.

To answer your original question, the "jQuery way" to do this would be
to use $.each(). If you wanted to achieve the closure in pure
JavaScript, you could do the following:

var i, len, myArray = ['one', 'two'], innerFunc;

innerFunc = function (i) {
    $.ajax({
        url : 'http://localhost/',
        complete : function () {
            alert(i);
        }
    });
}

for (i = 0, len = myArray.length; i < len; ++i) {
    innerFunc(i);
}

On Jan 28, 5:52 am, bob <xoxeo...@gmail.com> wrote:
> Thanks,
> Can't closure be achieved with for loop?
> for(var i=0; i<scripts.length; i++){
>
> My concern is:
> Does
> $.each
> process the "scripts" array items in the exact order they are in the
> array?

Reply via email to