您现在的位置是:首页 > 电脑技术查询 > web开发

高分,怎么把一个函数的参数原封不动传给另一个函数

编辑:chaxungu时间:2022-10-02 23:18:49分类:web开发

高分,如何把一个函数的参数原封不动传给另一个函数
function test()
{
// 众所周知, 我们可以通过arguments获得传入的所有参数
// getArguments(arguments); // 不符要求, b, c参数将为undefined
getArguments(这里怎么写?);
}

function getArguments(a, b, c)
{
// 众所周知, 我们可以通过arguments获得传入的所有参数
alert( "a: " + a + " b: " + b + " c: " + c);
}

test(1, 2, 3);

谢谢!

------解决方案--------------------
当然是拆开写呀,L@_@K

<script type= "text/javascript ">
<!--
function test()
{
// 众所周知, 我们可以通过 arguments 获得传入的所有参数
// getArguments(arguments); // 不符要求, b, c参数将为undefined
getArguments(arguments[0], arguments[1], arguments[2]);
}

function getArguments(a, b, c)
{
// 众所周知, 我们可以通过arguments获得传入的所有参数
alert( "a: " + a + " b: " + b + " c: " + c);
}

test(1, 2, 3);
//-->
</script>
------解决方案--------------------
试试apply

getArguments.apply(null,arguments);
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 传递参数 </title>
<script language= "javascript ">
function a(){
alert(arguments.length);
alert( "send arguments to b ");
b(arguments);
}

function b(){
for(var i=0;i <arguments[0].length;i++)
alert( "receive data: "+arguments[0][i]);
}

a(1,2,3,4,5);
</script>
</head>

<body>
</body>
</html>

------解决方案--------------------
<script type= "text/javascript ">

function test()
{

getArguments.apply(null,arguments);

}

function getArguments(a, b, c)
{

alert( "a: " + a + " b: " + b + " c: " + c);
}

test(4, 5, 6);

</script>
------解决方案--------------------
<script type= "text/javascript " language= "javascript ">
<!--
function test()
{
getArguments(arguments);
}

function getArguments(arg)
{
alert( "a: " + arg[0] + " b: " + arg[1] + " c: " + arg[2]);
}

test(1, 2, 3);
//-->
</script>