> From: Bob Nystrom <rnyst...@google.com>
> Date: July 19, 2011 2:31:48 GMT+02:00
> To: Brendan Eich <bren...@mozilla.com>
> Cc: es-discuss <es-discuss@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

a...@rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



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

Reply via email to