An "extend" operator is a natural companion to <|

Axel Rauschmayer axel at rauschma.de
Mon Jul 18 19:53:10 PDT 2011


> From: Bob Nystrom <rnystrom at google.com>
> Date: July 19, 2011 2:31:48 GMT+02:00
> To: Brendan Eich <brendan at mozilla.com>
> Cc: es-discuss <es-discuss at mozilla.org>
> Subject: Re: An "extend" operator is a natural companion to <|

To me, the important thing with class literals is to use naming consistently. If the class is named Point and you want to add properties to it, it seems odd to use an operator to add those properties to (what looks like) a method called "constructor". Under the hood, it makes sense. Superficially (with a sugared eye), it’s confusing.

> You could flip it around to:
> 
> class Point {
>   constructor(x, y) {
>     this.x = x;
>     this.y = y;
>   }
> 
>   zero() {
>     return new Point(0, 0);
>   }
> 
>   unit() {
>     return new Point(1, 1);
>   }
> 
>   prototype {
>     manhattanDistance() {
>       return Math.abs(this.x) + Math.abs(this.y);
>     }
>   }
> }


I kind of like the idea of parameterized object literals. But then I have no idea where class properties would go:

class Point(x,y) {
    x: x,
    y: y,
    prototype {
        manhattanDistance() {
            return Math.abs(this.x) + Math.abs(this.y);
        }
    }
}

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110719/8a14dfec/attachment-0001.html>


More information about the es-discuss mailing list