Skip to content

Instantly share code, notes, and snippets.

@caglarorhan
Last active January 5, 2022 22:31
Show Gist options
  • Save caglarorhan/6e9c04d04ced6d0cc9e97efe4f800f4b to your computer and use it in GitHub Desktop.
Save caglarorhan/6e9c04d04ced6d0cc9e97efe4f800f4b to your computer and use it in GitHub Desktop.
const account = {
balance: 0
};
const accountProcesses= {};
// Account processes - as many as we want
accountProcesses.deposit = {
process:(amount)=>{
account.balance += amount;
}
};
accountProcesses.withdraw = {
process:(amount)=>{
account.balance -= amount;
}
};
function doProcess(processType, amount) {
processType?.process(amount);
return account.balance;
}
console.log(doProcess(accountProcesses.deposit, 100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment