Last active
April 29, 2018 06:34
-
-
Save nairihar/d25f3574aa36f111c3337d7c658b662d to your computer and use it in GitHub Desktop.
Privates in JavaScript Classes, medium, using closures, es5
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
function Bank() { | |
// public variables | |
this.name = 'B7' | |
// public methods | |
this.getBalance = function() { | |
return _balance | |
} | |
this.addToBalance = function(count) { | |
_addBalance(count) | |
return this.getBalance() | |
} | |
// private variables | |
var _balance = 0 | |
var _logs = [] | |
// private methods | |
function _addBalance(count) { | |
_logBankChange('add', count) | |
_balance += count | |
} | |
function _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