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

Brendan Eich brendan at
Mon Jul 18 18:13:07 PDT 2011

On Jul 18, 2011, at 5:31 PM, Bob Nystrom wrote:

> 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);
>     }
>   }
> }
> Pros:
> 1. Makes it abundantly clear that prototype members are just that.

But that's not a good in itself, and your argument about many other languages putting "instance methods" at the level that this approach uses for class methods goes against.

> 2. Makes it clearer (I think?) that members on the constructor ("class") are that. Basically, the name of the surrounding curly ("prototype" or "class") tells you where the member goes.

This is a fair point but I think it is outweighed by the Cons (mine plus yours).

> Cons:
> 1. Prototype members, the most common case, are the most verbose and suffer two levels of indentation.

That's a problem too (in addition to the strangeness compared to other languages with 'class' syntax).

> 2. constructor() is in weird limbo. Should it be under prototype or class?

It binds a prototype property (MyDate.prototype.constructor), absent more magic to make that alias. It does not bind a class property (e.g., MyDate.constructor).

> 3. Lots'o'curlies.

This is a pain, but so are lots o' statics -- but generally class methods are few, so it could be a wash.

> There may be a good solution hiding in here somewhere, but I'm not sure.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list