[Harmony classes] method lexical scope for InstancePropertyDefinitions, PrototypePropertyDefinitions?

Gavin Barraclough barraclough at apple.com
Tue Jun 14 14:45:03 PDT 2011


Hi,

I was wondering whether there had been any discussion of bringing instance properties defined in the constructor into the lexical scope of methods , such that 'this.' and 'private(this).' overhead could be diminished?

For example, given the following class:

class Box {
    Box(x, y, z, density) {
        public x = x;
        public y = y;
        public z = z;
        private density = density;
    }

    public volume()
    {
        return this.x * this.y * this.z;
    }

    public weight()
    {
        return this.volume() * private(this).density;
    }
}

If instance properties are in scope the methods volume and weight could be written as:

    public volume()
    {
        return x * y * z;
    }

    public weight()
    {
        return this.volume() * density;
    }

Similarly, if prototype property definitions were brought into scope we could omit the 'this.' on the call to volume:

    public weight()
    {
        return volume() * density;
    }

Might this go some way towards resolving the verbosity of the use of private(this), currently listed as an open issue on the classes proposal, since in many methods these could be omitted?

cheers,
G.



More information about the es-discuss mailing list