intro
normally, when you write a function, you can call upon the arguments
array to loop through the arguments passed into the function as i did here with a function constant.
function foo () {
console.log(arguments);
}
foo(1);
fix
however, (fat) arrow functions () => {}
do not possess an arguments
object within their scope as the followin' will produce a reference error.
const foo = () => console.log(arguments);
foo(1);
however, the trick is to cleverly employ the spread operator to create a rest parameter. (technically, arrays are objects, so the rest parameter still counts as an arguments object)
const foo = (...args) => console.log(args);
foo(1);
happy codin'!
Top comments (0)