Rule proposal: `prefer-private-class-fields`
See original GitHub issuehttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields
Prefer private fields over the convention of underscore prefixed names.
This feature requires Node.js 12, so we cannot add it to the recommended preset until April 2021 (date of Node.js 10 obsoletion).
Does ESLint support this feature yet?
Fail
class Foo {
static _PRIVATE_STATIC_FIELD
_privateField
_privateMethod() {
return 'hello world'
}
}
Pass
class Foo {
static #PRIVATE_STATIC_FIELD
#privateField
#privateMethod() {
return 'hello world'
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Public and private instance fields proposal - TC39
This document attempts to integrate the public fields and private fields proposals into a single, coherent, orthogonal whole.
Read more >Setting up ESLint to work with new or proposed JavaScript ...
Setting up ESLint to work with new or proposed JavaScript features such as private class fields. It turns out configuring ESLint to use...
Read more >Class fields and private class members are now stage 4 ...
The basic design rule behind the private field proposal is: The presence or absence of a private field inside a class, can not...
Read more >Private fields, public worries. JavaScript — as a language
Consequently, the proposal allows us to declare class fields inside the ... Quite often you can see a class component defined like this:...
Read more >class - What are the differences between the private keyword ...
# -private fields provide compile-time and run-time privacy, which is not "hackable". It is a mechanism to prevent access to a member from ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@fisker I would argue having to use a
_
prefix to pseudo hide properties/methods is also awkward. I don’t think lack of destructuring is awkward enough to not use private fields. It’s just a minor inconvenience. Theproposal-destructuring-private
thing will probably not land in Node.js until Node.js 20 at the earliest, which means packages will not be able to use it until 2025.No longer blocked