5
Javascript : The Definitive Guide (2011)에는 엄격 모드에서는 작동하지 않지만 엄격 모드로 구현하는 방법은 나와 있지 않은이 예제가 있습니다. (p.186) - 시도 할 생각이 있지만 궁금합니다. 베스트 프랙티스/보안/성능 - 엄격 모드에서 이러한 일을하는 가장 좋은 방법은 무엇입니까? 코드는 다음과 같습니다.엄격 모드 : 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
@Raynos : 같아요 SO 대표 지점에 대한 그냥 관심이 없습니다. 기부를 원하는 다른 사람들에게 답변을 더 많이 초청합니다. –