Created
April 28, 2018 11:42
-
-
Save nairihar/11c8e509894f7a21a6923facee62c694 to your computer and use it in GitHub Desktop.
Privates in JavaScript Classes, medium, using closures, es6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// private variables | |
let _balance = 0 | |
let _logs = [] | |
export default class Bank { | |
constructor() { | |
// public variables | |
this.name = 'B7' | |
} | |
// public methods | |
getBalance() { | |
return _balance | |
} | |
addToBalance(count) { | |
_addBalance(count) | |
return this.getBalance() | |
} | |
} | |
// private methods | |
const _addBalance = (count) => { | |
_logBankChange('add', count) | |
_balance += count | |
} | |
const _logBankChange = (type, count) => { | |
_logs.push({ type, count }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment