Still not right. I screwed up the scoping of the "balance" variable.
Another correction coming soon.

On Thu, Jan 17, 2013 at 9:17 AM, Mark S. Miller <erig...@google.com> wrote:
> On Thu, Jan 17, 2013 at 9:13 AM, Andreas Rossberg <rossb...@google.com> 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



-- 
    Cheers,
    --MarkM
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to