mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-13 21:38:03 -05:00
Suggest using WeakMaps when hidden properties are needed
This updates the "trailing or leading underscores" guideline to suggest an better way to make properties hidden, as an alternative to just removing the underscore and making the property public.
This commit is contained in:
committed by
Jordan Harband
parent
aefff97bd1
commit
c5411a42d2
@@ -2993,6 +2993,11 @@ Other Style Guides
|
||||
|
||||
// good
|
||||
this.firstName = 'Panda';
|
||||
|
||||
// good, in environments where WeakMaps are available
|
||||
// see https://kangax.github.io/compat-table/es6/#test-WeakMap
|
||||
const firstNames = new WeakMap();
|
||||
firstNames.set(this, 'Panda');
|
||||
```
|
||||
|
||||
<a name="naming--self-this"></a><a name="22.5"></a>
|
||||
|
||||
Reference in New Issue
Block a user