FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Docs: clarify cases where traditional functions are preferred by Manvendra0023 · Pull Request #3221 · airbnb/javascript · GitHub

Docs: clarify cases where traditional functions are preferred - #3221

Draft
Manvendra0023 wants to merge 4 commits into
airbnb:masterfrom
Manvendra0023:docs-arrow-function-clarification
Draft

Docs: clarify cases where traditional functions are preferred#3221
Manvendra0023 wants to merge 4 commits into
airbnb:masterfrom
Manvendra0023:docs-arrow-function-clarification

Conversation

Copy link
Copy Markdown

This PR adds a small clarification to the Arrow Functions section describing cases where traditional functions are still preferred, such as function hoisting, dynamic this binding, and use of the arguments object.

The goal is to improve clarity without changing the existing recommendation.

ljharb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Arrow functions should only be used for inline callbacks. Everything else should use normal functions.

Comment thread README.md Outdated

Copy link
Copy Markdown
Author

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.

ljharb commented Jan 27, 2026

Copy link
Copy Markdown
Collaborator

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".

Copy link
Copy Markdown
Author

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.

Comment thread README.md Outdated
Co-authored-by: Jordan Harband <ljharb@gmail.com>

Copy link
Copy Markdown
Author

Thanks for the suggestion! Applied 👍

Comment thread README.md
Comment on lines +975 to +979
> // Dynamic `this` binding (e.g. event handlers)
> const button = document.querySelector('button');
>
> button.addEventListener('click', function () {
> this.classList.add('active');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this is actually not a good idea; in event handlers, you should use the event object argument's target or currentTarget instead of this.

ljharb marked this pull request as draft April 16, 2026 05:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL