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

xiaoyuehen 2007-08-16 11:56:32
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);

谢谢!
...全文
210 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
joohnnie 2007-08-17
  • 打赏
  • 举报
回复
试试apply

getArguments.apply(null,arguments);
yixianggao 2007-08-17
  • 打赏
  • 举报
回复
当然是拆开写呀,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>
xiaoyuehen 2007-08-17
  • 打赏
  • 举报
回复
原来如此!
经测试, 上面的代码都通过, 而且效果都不错..
ericloot(夏天到了) 的方式正中我下怀..呵呵..
谢谢大家了!!
给分, 结帖!
shuangbaby 2007-08-17
  • 打赏
  • 举报
回复
<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>
ericloot 2007-08-17
  • 打赏
  • 举报
回复
<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>
  • 打赏
  • 举报
回复
<!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>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧