Quick actions

cmd+k|ctrl+k

Navigation

Languages

hack OOP

Snippet info

Language

JavaScript

Visibility

public

Author

mjg.py3

Created

2017-05-31T03:10:10Z

Updated

2017-05-31T03:10:10Z


function Account(balance) {
  return function(message, args) {
    if (message === 'deposit') {
      balance += args[0];
    }
    if (message === 'withdraw') {
      balance -= args[0];
    }
    if (message === 'balance') {
      return balance;
    }
  };
}

var myAccount = Account(42);

console.log(myAccount('balance'));

myAccount('deposit', [3]);

console.log(myAccount('balance'));
INFO