On Thu, Jan 17, 2013 at 9:13 AM, Andreas Rossberg <[email protected]> wrote:
> Hm, I'm afraid I don't fully understand that example. There seems to
> be a missing closing brace for the constructor, and I don't know what
> the free occurrences of 'balance' are referring to. Also, the second
> line of the deposit function seems to be missing in the expansion.
You're right. I also forgot a "new". Corrected I think:
class Purse {
constructor(private balance) {}
getBalance() { return balance; }
makePurse() { return new Purse(0); }
deposit(amount, srcPurse) {
private(srcPurse).balance -= amount;
balance += amount;
}
}
expansion
let Purse = (function() {
let amp = WeakMap();
function Purse(balance) {
amp.set(this, Object.seal({
get balance() { return balance; },
set balance(newBalance) { balance = newBalance; }
}));
}
Purse.prototype = {
getBalance: function() { return balance; },
makePurse: function() { return new Purse(0); },
deposit: function(amount, srcPurse) {
amp.get(srcPurse).balance -= amount;
balance += amount;
}
}
return Purse;
})();
Please let me know if anything else remains mysterious or looks wrong.
--
Cheers,
--MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss