开发者

javascript array parameter list [duplicate]

开发者 https://www.devze.com 2023-01-19 13:30 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Calling dynamic function with dynamic parameters in Javas开发者_StackOverflow社区cript
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Calling dynamic function with dynamic parameters in Javas开发者_StackOverflow社区cript

I have an array representing the parameters I need to pass to a function call. How can I construct this function call dynamically?

e.g.

function constructRequest(params) {
   //params is an array of params to be sent to myFunction()

   myFunction(params[0],params[1], ... , params[i]);

   //myFunction() needs to have the array deconstructed and is ready 
   // to accept optional params
}

Thanks


Use arguments:

function A()
{
    alert( arguments[0] ); // 1
    alert( arguments[1] ); // 2
    alert( arguments[2] ); // 3
}

A(1, 2, 3);

More info on MDC (Mozilla Develop Center).

0

精彩评论

暂无评论...
验证码 换一张
取 消