5
Javascript:權威指南(2011)有這個例子(第186頁),它不能在嚴格模式下工作,但沒有說明如何在嚴格模式下實現它 - 我可以考慮要嘗試的東西,但我想知道最佳實踐/安全/性能 - 在嚴格模式下做這種事情的最佳方式是什麼?這裏的代碼:Strict-Mode:替代argument.callee.length?
// 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.
}
爲什麼社區維基一切 – Raynos 2012-04-08 23:46:26
@Raynos:只是不關心SO代表處點我猜。使答案更吸引其他想要貢獻的人。 – 2012-04-08 23:49:56