In the following function, I return a function. This returned function tries to access 'arguments', but for some reason that references the outer function's 'arguments', not its own arguments. I know this is because it is an arrow function, so bound to the outer function, but don't feel satisfied that this is a good enough understanding. Could you explain why and also how to access the inner functions 'arguments'
function add() {
let pa = arguments;
if(arguments.length>1){
return "regular function"
}else{
return ()=>{
return "curried function with " + pa + " and " + arguments;
}
}
}
I know that returning a named hoisted function fixes this:
function add() {
let pa = arguments;
if(arguments.length>1){
return "regular function"
}else{
return function curried(){
return "curried function with " + pa + " and " + arguments;
}
}
}
I would still like a clearer way of thinking about the arrow function, and how to access local arguments in the arrow function.