Skip to content

Commit

Permalink
docs: Add private class features info to no-underscore-dangle
Browse files Browse the repository at this point in the history
  • Loading branch information
matwilko committed Jul 18, 2023
1 parent 42faa17 commit 14071a0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/src/rules/no-underscore-dangle.md
Expand Up @@ -10,9 +10,11 @@ As far as naming conventions for identifiers go, dangling underscores may be the
var _foo;
```

There is actually a long history of using dangling underscores to indicate "private" members of objects in JavaScript (though JavaScript doesn't have truly private members, this convention served as a warning). This began with SpiderMonkey adding nonstandard methods such as `__defineGetter__()`. The intent with the underscores was to make it obvious that this method was special in some way. Since that time, using a single underscore prefix has become popular as a way to indicate "private" members of objects.
There is a long history of using dangling underscores to indicate "private" members of objects in JavaScript, with the intent to make it obvious that the property or method is special in some way.

Whether or not you choose to allow dangling underscores in identifiers is purely a convention and has no effect on performance, readability, or complexity. It's purely a preference.
ES2022/ES13 has since introduced [Private class features](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields), with broad ecosystem support. It is recommended you use those features where possible as they provide truly private members.

Allowing dangling underscores in identifiers is purely a convention and has no effect on performance, readability, or complexity. However, they do not have the same encapsulation benefits as private class features, even with this rule enabled.

## Rule Details

Expand Down

0 comments on commit 14071a0

Please sign in to comment.