From 25a7e4c4de61f26468b238c8297f181d7b20cd06 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 16 Jul 2018 10:28:55 -0700 Subject: [PATCH] Update JS style guide with rule for prefixing private class methods with an underscore. --- style_guides/js_style_guide.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/style_guides/js_style_guide.md b/style_guides/js_style_guide.md index 1354f67009235..8a449230e70dd 100644 --- a/style_guides/js_style_guide.md +++ b/style_guides/js_style_guide.md @@ -215,6 +215,20 @@ class bank_account {} class bankAccount {} ``` +## Prefix private class methods with an underscore + +Identifying private class methods makes it easier to differentiate a class's public and internal +APIs, and makes private methods easier to mark as `private` when the code is migrated to TypeScript. + +```js +// good +class BankAccount { + addFunds() {} + + _calculateInterest() {} +} +``` + ## Magic numbers/strings These are numbers (or other values) simply used in line in your code. *Do not