arguments.lengthとarguments.callee.lengthを用いた引数チェック
arguments.lengthとarguments.callee.lengthは違う。
前者は、呼び指しされた際に割り当てられた引数の個数。
後者は、関数の定義してある引数の個数。
これらの値を比較してあげることで引数チェックが可能になる。
function check(args){ if(args.length === args.callee.length){ alert("same!!"); }else{ throw new Error("Request Arguments : " + args.callee.length + " but Your Arguments : " + args.length); } } function hoge(x, y, z){ try{ check(arguments); }catch(e){ console.debug(e); }finally{ return x + y + z; } } console.debug(hoge(1,2,3,4));