Arguments in ES6 Arrow Functions: Official Clarification
In ES6 arrow functions, the behavior of the arguments keyword has been a topic of debate. Some browsers and platforms (such as Chrome, Firefox, and Node) deviate from the initial TC39 recommendations, raising questions about the correct interpretation of the specification.
According to the official ES6 specification, arrow functions do not have their own arguments binding within their scope. When invoked, arrow functions do not create an arguments object as part of the declaration instantiation process.
This contradicts the behavior observed in browsers such as Chrome, Firefox, and Node, which create an arguments object in arrow functions. As a result, these browsers incorrectly provide access to the arguments passed to the enclosing function.
Babel, on the other hand, follows the official specification by throwing a "ReferenceError" when arguments is accessed inside an arrow function. This aligns with the intended behavior of arrow functions as functions that adopt their parent scope for arguments access.
Therefore, the correct understanding is that arrow functions do not have a dedicated arguments binding. Developers should use the arguments object provided by the enclosing function to access passed arguments when working with arrow functions.
The above is the detailed content of When Do Arrow Functions or the Parent Scope Define the Arguments of a Function?. For more information, please follow other related articles on the PHP Chinese website!