File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -946,6 +946,35 @@ const bankAccount = new BankAccount();
946946
947947// Buy shoes...
948948bankAccount .withdraw (100 );
949+ ```
950+
951+ ** Good with getter/setter** :
952+ ``` javascript
953+ class BankAccount {
954+ constructor (balance = 1000 ) {
955+ this_balance = balance;
956+ }
957+
958+ // It doesn't have to be prefixed with `get` or `set` to be a getter/setter
959+ set balance (amount ) {
960+ if (verifyAmountCanBeSetted (amount)) {
961+ this ._balance = amount;
962+ }
963+ }
964+
965+ get balance () {
966+ return this ._balance ;
967+ }
968+ }
969+
970+ const bankAccount = new BankAccount ();
971+
972+ // Buy shoes...
973+ bankAccount .balance -= shoesPrice;
974+
975+ // Get balance
976+ let balance = bankAccount .balance ;
977+
949978```
950979** [ ⬆ back to top] ( #table-of-contents ) **
951980
You can’t perform that action at this time.
0 commit comments