Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need and advice.

This is my issue, I have "N" functions.

 var FirstOne  = function(){
    return $.ajax({
        type: "POST",
        url: hrefUrl,
        data: JSON2.stringify(option),
        contentType: "application/json; charset=utf-8",
        dataType: "json",           
        error: function(status){
        },
        success: function(data){    
        }
    });
};

var SecondOne  = function(){

    return $.ajax({
        type: "POST",
        url: hrefUrl,
        data: JSON2.stringify(option2),
        contentType: "application/json; charset=utf-8",
        dataType: "json",           
        error: function(status){
        },
        success: function(data){    
        }
    });
};


.............


var NOne  = function(){

    return $.ajax({
        type: "POST",
        url: hrefUrl,
        data: JSON2.stringify(optionn),
        contentType: "application/json; charset=utf-8",
        dataType: "json",           
        error: function(status){
        },
        success: function(data){    
        }
    });
};

all these function arr pushed in an object which is this .

var funcObject= [FirstOne(), SecondOne(), ....... NOne() ];

after I am waiting when all Ajax functions are done with and and after I am fine.

    $.when.apply($, funcObject).done(function (a1, a2, ...an) {
 //        ..... here already doesn't matter

    });

my issue is here:

function (a1, a2, ...an)

I want to have instead function arguments an object because I do not know how many function is going to be.

So i can edit function object, which is cool $.when.apply($, fucArr), problem is to use variable numbers of arguments .

PS: Maybe I can use "apply" or "call" for these arguments as well?

Can someone give me an idea here. Thanks A lot guys!!!

share|improve this question
    
possible duplicate of Allowing javascript function to accept any number of arguments and many others. –  Felix Kling Feb 14 '12 at 16:19

1 Answer 1

up vote 9 down vote accepted

You can access all arguments passed to a method using the arguments keyword eg:

function () {
  Console.log(arguments); //arguments is an array
}

The apply method can be used to use these arguments in another function call:

function () {
  someFunction.apply(this, arguments);
}
share|improve this answer
1  
Blimey that's useful :) –  bukko Feb 14 '12 at 16:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.