Javascript: The Definitive Guide (2011) にはこの例 (p.186) があり、厳密モードでは機能しませんが、厳密モードでの実装方法は示されていません。試してみることはできますが、ベスト プラクティスについて疑問に思っています。 /security/performance -- 厳密モードでこの種のことを行う最善の方法は何ですか? コードは次のとおりです。
// This function uses arguments.callee, so it won't work in strict mode.
function check(args) {
var actual = args.length; // The actual number of arguments
var expected = args.callee.length; // The expected number of arguments
if (actual !== expected) // Throw an exception if they differ.
throw Error("Expected " + expected + "args; got " + actual);
}
function f(x, y, z) {
check(arguments); // Check that the actual # of args matches expected #.
return x + y + z; // Now do the rest of the function normally.
}