class sugar

Mark S. Miller erights at google.com
Sat Jun 4 00:24:33 PDT 2011


On Sat, Jun 4, 2011 at 12:04 AM, Mark S. Miller <erights at google.com> wrote:

>
>>
>> closure-based system ----------------------------------
>>
>> function makePoint(x, y) {
>>    return {
>>        getDistance: function() {
>>            return Math.sqrt(x * x + y * y);
>>        }
>>    };
>> }
>>
>
>
> which can be expressed in classes as:
>
>   class Point {
>     constructor(x, y) {
>       public getDistance() {
>         return Math.sqrt(x * x + y * y);
>       }
>     }
>   }
>

Btw, I'd like to thank you again for having made the suggestion at <
https://mail.mozilla.org/pipermail/es-discuss/2008-November/008185.html> for
supporting objects-as-closure with a "public" annotated declaration in what
was essentially a block body. This suggestion survived through many class
strawmen and is now in the promoted proposal.

-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110604/a7e3b173/attachment.html>


More information about the es-discuss mailing list