JS関数のパラメータの使用
1322 ワード
JS関数のパラメータはfunction内でargumentsオブジェクトで取得できます.パラメータの呼び出しには2つの方法がある:1、所望のパラメータの使用.2、実際の伝達パラメータの使用.適用例:function Test(a,b){var i,s=「Test関数あり」;var numargs=arguments.length;//実際に渡されたパラメータの数値を取得する.var expargs=Test.length;//所望のパラメータの数値を取得し、関数定義時の所望のパラメータ個数(aとbの2つのパラメータあり).s+=(expargs+「個のパラメータ」);s+="for(i=0;iコードデモ
<html>
<head>
<script language="javascript">
function reloadList(){
if(typeof arguments[0] == "function"){
arguments[0].call(this);
arguments[0]();
}
if(typeof arguments[0] == "string")
alert(arguments[0]);
if(typeof arguments[0] == "number")
alert(arguments[0]);
if(typeof arguments[0] == "undefined")
alert(arguments[0]);
if(typeof arguments[0] == "boolean")
alert(arguments[0]);
if(typeof arguments[0] == "null")
alert(arguments[0]);
}
reloadList(function(){});
</script>
</head>
<body>
</body>