Javascript: The Definitive Guide (2011) ha questo esempio (p.186) che non funziona in modalità rigorosa ma non mostra come implementarlo in modalità rigorosa - Posso pensare a cose da provare ma mi sto chiedendo best practice/sicurezza/prestazioni - qual è il modo migliore per fare questo genere di cose in modalità rigorosa? Ecco il codice:Modalità rigorosa: alternativa a 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.
}
perché comunità wiki tutto – Raynos
@Raynos: Basta che non preoccupa SO punti rep credo. Rende la risposta più invitante per gli altri che vogliono contribuire. –