var Account = function (bal, yes, no) { return { balance: function () {print(bal);}, deposit: function (x) {bal = bal + x; yes();}, withdraw: function (x) { if (bal < x) {no();} else {bal = bal - x; yes();} } } } woohoo = function () {print("Woohoo! It worked :-)");} sigh = function () {print("Oh no. It failed :-(");} a = Account(100, woohoo, sigh); a.deposit(10); a.withdraw(300);
Output