如何在JavaScript函数中使用无限参数?
要使用不限数量的参数来运行,请使用arguments对象。
示例
您可以尝试运行以下代码以在JavaScript中实现函数的无限参数
<html>
<body>
<script>
function functionArgument(val1, val2, val3){
var res = "";
res += "Expected Arguments: " + functionArgument.length;
res += "<br />";
res += "Current Arguments : " + arguments.length;
res += "<br />";
res += "Each argument = "
for (p = 0; p < arguments.length; p++){
res += "<br />";
res += functionArgument.arguments[p];
res += " ";
}
document.write(res);
}
functionArgument(20, 50, 80, "演示文字!","Hello World", new Date())
</script>
</body>
</html>热门推荐
10 离别简短的祝福语大全
11 接亲新郎进门祝福语简短
12 女朋友考试祝福语简短
13 订婚新发言简短祝福语
14 团队文案祝福语简短励志
15 开店大吉文案祝福语简短
16 诗词送行祝福语大全简短
17 宝宝周岁敬酒祝福语简短
18 生日牌祝福语英语简短