Java Reference
In-Depth Information
Warning:
arguments
Object Cannot Be Trapped
in a Closure
The
arguments
object cannot be trapped in a closure and returned in a
function as it is not available inside nested functions. Hence, the following
would fail:
function multiplier(){
return function(x){
return x * arguments[0]; // arguments is not
available
↵
in this nested function
}
}
This can be fixed by using another closure:
function multiplier(){
var args = arguments; // the variable args
will be
↵
available in the return function
return function(x){
return x * args[0];
}
}
Check out this useful video about closures on
Learnable.
