■不特定数の引数を処理したい


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>不特定数の引数を処理したい</title>
<script type="text/JavaScript">
<!--
function calc1(j,k) {
document.write("指定された引数の数 = "+calc1.arguments.length+"<br>");
return(j + k);
}
function calc2() {
document.write("指定された引数の数 = "+calc2.arguments.length+"<br>");
add = 0;
for (i = 0; i < calc2.arguments.length; i++) {
document.write("calc2.arguments["+i+"] = "+calc2.arguments[i]+"<br>");
add = add + calc2.arguments[i];
}
return(add);
}
// -->
</script>
<body>
<p>■不特定数の引数を処理したい</p>
<script type="text/JavaScript">
<!--
document.write("<p>「function calc1(j,k)」が本来要求する引数の数 = "+calc1.length+"<br>");
document.write("<p>calc1(10,20,30,40)の結果 = "+calc1(10,20,30,40)+"</p>");
document.write("<hr>");
document.write("<p>「function calc2()」が本来要求する引数の数 = "+calc2.length+"<br>");
document.write("<p>calc2(10,20,30,40)の結果 = "+calc2(10,20,30,40)+"</p>");
// -->
</script>
</body>
</html>



★解説★