-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Docs: clarify cases where traditional functions are preferred #3221
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
base: master
Are you sure you want to change the base?
Docs: clarify cases where traditional functions are preferred #3221
Conversation
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrow functions should only be used for inline callbacks. Everything else should use normal functions.
|
Thanks for the clarification — that makes sense. I agree that this guide should not encourage relying on hoisting, and that arrow functions should generally be preferred except for inline callbacks. My intent here wasn’t to recommend hoisting as a practice, but to document why traditional functions still exist and what technical differences remain, for readers who may encounter them in real codebases. I’m happy to remove or reword the hoisting mention to avoid implying it’s an acceptable pattern under this guide. Please let me know if you’d prefer the section to focus only on cases like named functions for debugging / stack traces, or if you’d rather drop the section entirely. |
|
I think that instead of "here's when you shouldn't use arrow functions", i think more useful guidance is "here are the only places you should use arrow functions". |
|
That makes sense — I agree that framing this in terms of “where arrow functions should be used” is clearer and more in line with the guide’s intent. I’ll update the section to focus on a short, explicit list of recommended arrow function use cases (e.g. inline callbacks), and remove or de-emphasise the “when not to use” framing. I’ll push an update shortly — thanks for the guidance. |
|
|
||
| > Why not? If you have a fairly complicated function, you might move that logic out into its own named function expression. | ||
|
|
||
| > **Note:** Arrow functions are intended primarily for short, anonymous callbacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| > **Note:** Arrow functions are intended primarily for short, anonymous callbacks. | |
| > **Note:** Arrow functions are intended primarily for inline, anonymous callbacks. |
This PR adds a small clarification to the Arrow Functions section describing cases where traditional functions are still preferred, such as function hoisting, dynamic
thisbinding, and use of theargumentsobject.The goal is to improve clarity without changing the existing recommendation.