javascriptecmascript-6arrow-functionsarguments-object

Official information on `arguments` in ES6 Arrow functions?


(() => console.log(arguments))(1,2,3);

// Chrome, FF, Node give "1,2,3"
// Babel gives "arguments is not defined" from parent scope

According to Babel (and from what I can tell initial TC39 recommendations), that is "invalid" as arrow functions should be using their parent scope for arguments. The only info I've been able to find that contradicts this is a single comment saying this was rejected by TC39, but I can't find anything to back this up.

Just looking for official docs here.


Solution

  • Chrome, FF, and node seem to be wrong here, Babel is correct:

    Arrow functions do not have an own arguments binding in their scope; no arguments object is created when calling them.

    looking for official docs here

    Arrow function expressions evaluate to functions that have their [[ThisMode]] set to lexical, and when such are called the declaration instantiation does not create an arguments object. There is even a specifc note (18 a) stating that "Arrow functions never have an arguments objects.".