Classes: suggestions for improvement

Juan Ignacio Dopazo dopazo.juan at gmail.com
Sun Jun 12 16:54:11 PDT 2011


On Sun, Jun 12, 2011 at 6:38 PM, Brendan Eich <brendan at mozilla.com> wrote:

> On Jun 12, 2011, at 2:22 PM, Axel Rauschmayer wrote:
>
> (1) The syntax for private properties still is a bit clumsy, and @ feels
> like wasting a nice symbol, how about using private.foo instead of
> private(this).foo?
>
>
> No, you need private(other).foo or shorter for things like
>
>  class Point {
>    constructor(x, y) {
>      private x = x;
>      private y = y;
>    }
>    equals(p) { return
> private(this).x === private(p).x && private(this).y === private(p).y; }
>    ...
>  }
>
If I understand correctly the reason for needing private(this).x is because
the private names proposal allows having a private name with the same name
as a common property.

Also IIRC , this is a result of putting instance properties in the
constructor. Because of that the private name lives in the scope of the
constructor and not in the scope of the class. So would this be correct?

class Monster {
    private jump() {
        console.log('jump!');
    }
    constructor() {
        this.jump();
    }
}

Juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110612/e922b140/attachment.html>


More information about the es-discuss mailing list