1

This seems so super strange.

I have the following

$.when.apply(null, arrayOfDeferredObjects).then(function(result)) {
    if (1 == arrayOfDeferredObjects.length){
       //stuff done here
    }
    else{
        for (var index = 0; index < contentUnits.length; index++) {
            if(arguments && arguments[index][0] && arguments[index][0].response) {
               //stuff done here
            }
        };
    }

My expectation is that arguments will be an array of 1 object for 1 call in the array of Deferreds and an array of X objects for X calls in the deferred array.

I know why this is happening but it frustrates me to do that check for the length of the array. Arguments isn't an array when there is only 1 object and is where there is more than 1. That's obvious. Is there anything I can do to make the parameter returned not just represent the first call?

1 Answer 1

1

Arguments, like this, always reflects the context of the immediate function and never references outside context. You also used a reference to the original array, which does not change based on this code.

Your original array and the Arguments object are not the same thing, they merely have the same object references as members. Arguments is never an array and always has a length property (based on your statements, I think you're making some false assumptions about arguments).

The arguments in the then function parameter will vary depending on the type and number of deferreds in the when invocation. See the spec.

Lastly, I can't actually post working code for you since the iterated ContentUnits variable is not shown.

I think there is a better way to do what you're trying to do, only you didn't actually say what you were trying to do. I think there is a by

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.