JSFiddle - React, Tailwind, and code Playground
by scriptstar
HTML
<input type="text" id="edb">
JavaScript
var account = { balance:0, withdraw: 0, deposit: 0 }
var updateBalance = function(withdraw, deposit, blah){
this.withdraw = withdraw;
this.deposit = deposit;
this.balance = this.balance + this.deposit;
var accBalance = this.balance - this.withdraw;
if (accBalance <= 0){
alert ("Sorry, your balance is low");
}
else{
this.balance = this.balance - this.withdraw;
}
$("#edb").val( this.balance );
}
var transaction = function(account, method, args){
method.apply(account, args);
}
updateBalance.call(account, 1200, 2000); //balance will be 800 after this statement
transaction(account, updateBalance, [400, 2000]); //balance will be 2400 after this statement