Skip to content

Discussion: Arrow Functions vs Traditional Functions #3121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fisker0303 opened this issue Apr 25, 2025 · 1 comment
Open

Discussion: Arrow Functions vs Traditional Functions #3121

fisker0303 opened this issue Apr 25, 2025 · 1 comment
Labels

Comments

@fisker0303
Copy link

The style guide recommends using arrow functions for anonymous functions (Section 8.1). While I agree with this recommendation, I think it would be helpful to add more examples showing when traditional functions might still be preferred, such as:

  1. When you need the function to be hoisted
  2. When you need to use this binding differently
  3. When you need the arguments object

What do you think about adding these clarifications?

@ljharb
Copy link
Collaborator

ljharb commented Apr 25, 2025

This guide strictly forbids relying on hoisting, and you can use rest syntax if you need all the unnamed arguments.

Basically any time a function isn’t an inline callback, it should be a traditional function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants