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:
Teddy Katz
2018-02-04 17:11:01 -05:00
committed by Jordan Harband
parent aefff97bd1
commit c5411a42d2

View File

@@ -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>