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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3